JESS: Problem with Input Router?

View: New views
2 Messages — Rating Filter:   Alert me  

JESS: Problem with Input Router?

by Bang Bui :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello
This is my problem:
I have a rule:  (defrule Rule1 => (printout t "Enter a number")  (readline t))
I want "Enter a number" is printed in a TextArea and input a number in a TextField. I set the TextArea is the output router and TextField is the input router. When I run my program, "Enter a number" was displayed in the TextArea but my program was locked. I couldn't input anything into the TextField.
Please help me.
I'm so sorry for my English.
 
Thanks a lot! 
 
Here is apart of my program.
public class frmExample1 extends javax.swing.JFrame
{
    Rete engine;
    TextReader tr;
    TextAreaWriter taw;
    public frmExample1()
   {
        initComponents();
        engine=new Rete();
        taw=new TextAreaWriter(taQuestion);
       //taQuestion is a TextArea
        engine.addOutputRouter("t", taw);
        engine.addOutputRouter("WSTDOUT", taw);
        engine.addOutputRouter("WSTDERR", taw);
        tr=new TextReader(false);
        engine.addInputRouter("t", tr, true);
        engine.addInputRouter("WSTDIN", tr, true);
        try
        {
            engine.eval("(defrule Rule1 => (printout t 'Enter a number')(readline t))");
        }catch(Exception e){System.out.println(e.toString());}
        engine.reset();
        engine.run();
    }
    private void txtAnswerActionPerformed(java.awt.event.ActionEvent evt)
   {                                           
         tr.appendText(txtAnswer.getText() + "\n");
         txtAnswer.setText("");
         //txtAnswer is a TextField
   }
}
 


Địa chỉ email mới dành cho bạn!
Chọn ngay một tên truy nhập bạn từng muốn lập với tên miền mới ymail và rocketmail.
Nhanh nhanh trước khi có người xí mất!

Re: JESS: Problem with Input Router?

by Ernest Friedman-Hill :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

How does "txtAnswerActionPerformed" get called? Is there a real  
actionPerformed() method somewhere that calls it?

You're running the whole application inside the JFrame's consructor;  
thinking about it, this would probably work, but it's highly unusual.  
Normally, we let constructors complete rather than invoking a long-
running process from them.

When you create

On Jun 27, 2009, at 11:51 PM, Bang Bui wrote:

> Hello
> This is my problem:
> I have a rule:  (defrule Rule1 => (printout t "Enter a number")  
> (readline t))
> I want "Enter a number" is printed in a TextArea and input a number  
> in a TextField. I set the TextArea is the output router and  
> TextField is the input router. When I run my program, "Enter a  
> number" was displayed in the TextArea but my program was locked. I  
> couldn't input anything into the TextField.
> Please help me.
> I'm so sorry for my English.
>
> Thanks a lot!
>
> Here is apart of my program.
> public class frmExample1 extends javax.swing.JFrame
> {
>     Rete engine;
>     TextReader tr;
>     TextAreaWriter taw;
>     public frmExample1()
>    {
>         initComponents();
>         engine=new Rete();
>         taw=new TextAreaWriter(taQuestion);
>        //taQuestion is a TextArea
>         engine.addOutputRouter("t", taw);
>         engine.addOutputRouter("WSTDOUT", taw);
>         engine.addOutputRouter("WSTDERR", taw);
>         tr=new TextReader(false);
>         engine.addInputRouter("t", tr, true);
>         engine.addInputRouter("WSTDIN", tr, true);
>         try
>         {
>             engine.eval("(defrule Rule1 => (printout t 'Enter a  
> number')(readline t))");
>         }catch(Exception e){System.out.println(e.toString());}
>         engine.reset();
>         engine.run();
>     }
>     private void txtAnswerActionPerformed(java.awt.event.ActionEvent  
> evt)
>    {
>          tr.appendText(txtAnswer.getText() + "\n");
>          txtAnswer.setText("");
>          //txtAnswer is a TextField
>    }
> }
>
>
> Địa chỉ email mới dành cho bạn!
> Chọn ngay một tên truy nhập bạn từng muốn lập với  
> tên miền mới ymail và rocketmail.
> Nhanh nhanh trước khi có người xí mất!

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com







--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------