问题描述
我正在尝试从规则的Jess RHS获取打印输出内容.这里描述了一个类似的问题: Java中JESS的输出,但没有具体的说明解决方案如何将路由器用于printout命令.与其在Java控制台中打印规则的打印输出内容,不如在专用的JTextArea中打印它们.我声明了一个字符串String result;
保留内容,然后通过outputTxt.setText(result);
I am trying to get the printout contents from a Jess RHS of a rule. A similar question is described here: Output of JESS in Java but there is not a concrete solution how to use a router for the printout command. Instead of printing the rule's printout contents in Java console I want to print them in a dedicated JTextArea. I declared a string e.g. String result;
to hold the contents and then print out the string contents into JTextArea through outputTxt.setText(result);
推荐答案
Jess手册明确讨论了这种情况.参见 http://www.jessrules.com/jess/docs/71/library.html#routers 和 http://www.jessrules .com/jess/docs/71/library.html#reader .真的再简单不过了:
The Jess manual discusses exactly this case, explicitly; see http://www.jessrules.com/jess/docs/71/library.html#routers and http://www.jessrules.com/jess/docs/71/library.html#reader . It really couldn't be easier:
// 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打印输出内容以Java打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!