问题
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