0

我正在尝试从规则的 Jess RHS 获取打印输出内容。此处描述了一个类似的问题:Output of JESS in Java but there is not a specific solution how to use a router for the printout command。我不想在 Java 控制台中打印规则的打印输出内容,而是想在专用的 JTextArea 中打印它们。我声明了一个字符串,例如String result;保存内容,然后通过将字符串内容打印到 JTextAreaoutputTxt.setText(result);

4

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);
于 2015-04-26T18:45:59.200 回答