Jess 打印输出内容打印在 Java
Jess printout contents print in Java
我正在尝试从规则的 Jess RHS 中获取打印输出内容。此处描述了一个类似的问题:Output of JESS in Java 但没有具体的解决方案如何使用路由器执行打印输出命令。我不想在 Java 控制台中打印规则的打印输出内容,而是想在专用的 JTextArea 中打印它们。我声明了一个字符串,例如String result;
保存内容然后通过outputTxt.setText(result);
将字符串内容打印到JTextArea中
Jess 手册明确讨论了这种情况;见 http://www.jessrules.com/jess/docs/71/library.html#routers and http://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);
我正在尝试从规则的 Jess RHS 中获取打印输出内容。此处描述了一个类似的问题:Output of JESS in Java 但没有具体的解决方案如何使用路由器执行打印输出命令。我不想在 Java 控制台中打印规则的打印输出内容,而是想在专用的 JTextArea 中打印它们。我声明了一个字符串,例如String result;
保存内容然后通过outputTxt.setText(result);
Jess 手册明确讨论了这种情况;见 http://www.jessrules.com/jess/docs/71/library.html#routers and http://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);