有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

netbeans Jess打印输出内容用Java打印

我正试图从Jess RHS的规则中获取打印内容。这里描述了一个类似的问题:Output of JESS in Java但是没有一个具体的解决方案如何使用路由器来执行打印输出命令。我不想在Java控制台中打印规则的打印输出内容,而是想在专用的JTextArea中打印它们。我声明了一个字符串,例如String result;来保存内容,然后通过outputTxt.setText(result);将字符串内容打印到JTextArea中


共 (1) 个答案

  1. # 1 楼答案

    Jess手册明确地讨论了这个案例;见http://www.jessrules.com/jess/docs/71/library.html#routershttp://www.jessrules.com/jess/docs/71/library.html#reader。这真是再容易不过了:

     // Create a text area; you'll need to add it to your GUI, of course
     TextArea ta = new TextArea(20, 80);
     // This is a sort of adapter that lets Jess print into a textarea.
     // There's also a JTextAreaWriter for Swing GUIs
     TextAreaWriter taw = new TextAreaWriter(ta);
     // Create a rule engine instance
     Rete engine = new Rete();
     // Connect the "t" router to the TextArea. From this point on, 
     // Jess code that executes "(printout t ..." will send its output
     // to the TextArea
     engine.addOutputRouter("t", taw);