Jess printout contents print in Java

时间秒杀一切 提交于 2019-12-13 05:04:12

问题


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);


回答1:


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);


来源:https://stackoverflow.com/questions/29871782/jess-printout-contents-print-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!