Jess打印输出内容用Java打印

时间:2015-04-25 23:14:02

标签: java netbeans jess

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

将字符串内容打印到JTextArea中

1 个答案:

答案 0 :(得分: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);