Console.execute() is an infinite loop:

  public void execute(String [] argv) {
    Main m = new Main();
    m.initialize(argv, m_rete);
    m_panel.setFocus();
    while (true)
      m.execute(m_doEcho);
  }

This means that whatever thread calls it will never return (well,
unless a java.lang.Error is thrown.) You're calling it from the GUI
event-handling thread, which is obviously bad -- once you call it, the
GUI can't respond to any more events.

There are a couple different things you could do. First of all, you
need to doing the actual running of the engine on a dedicated
thread. Second, rather than creating a new Console and then destroying
it, you could simply hide it when it's not needed. So, you might change
your event handler to look something like this:

        // This is now a member variable, not a local
        Console c;
        ...
        case JESS_PROMPT:
                if (c == null) {
                  c = new Console("Agent - Jess engine", m_rete, true);
                  c.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent event) {
                          c.setVisible(false);
                    }
                  });
                  String[] argv = new String[0];
                  new Thread(new Runnable() {
                    public void run() {
                      c.execute(argv);
                    }
                  }.start();
                }
                c.setVisible(true);
                break;


I think Sander Faas wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hello,
> 
> My agent has a Rete engine (m_rete) that I wish to access through a Console.
> Therefore the agent's GUI has a menubar with an item "Jess prompt". The
> eventhandler for this item contains the following code in the switch
> statement:
> 
>       case JESS_PROMPT:
>               final Console c = new Console("Agent - Jess engine", m_rete, true);
>               c.addWindowListener(new WindowAdapter()
>               {
>                       public void windowClosing(WindowEvent event)
>                       {
>                               c.setVisible(false);
>                               c.dispose();
>                       }
>               });
>               String[] argv = new String[0];
>               c.execute(argv);
>               break;
> 
> This works fine, but after I have closed the console window, I am unable to
> open it again. Furthermore it seems as if my GUI refuses to handle any
> events (for example from other items in the menubar) after using the
> console. Does anyone have a clue to the cause of this problem? Is something
> wrong with the code above?
> 
> Greetings,
> Sander
> 
> 
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the list
> (use your own address!) List problems? Notify [EMAIL PROTECTED]
> --------------------------------------------------------------------
> 



---------------------------------------------------------
Ernest Friedman-Hill  
Distributed Systems Research        Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
Org. 8920, MS 9012                  [EMAIL PROTECTED]
PO Box 969                  http://herzberg.ca.sandia.gov
Livermore, CA 94550

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to