First of all,
you should never do anything so time-consuming as running a rule engine inside an event handler, because while an event handler is running, no other GUI actions (including repainting the screen, or handling other events) can occur. Furthermore, if you're running an inference engine in an event handler, than nothing you can implement via another button push can possibly have any effect on that engine, because, as I said, while the first event handler is running, no other event handlers can be serviced. Your "halt" call can't execute until after the inference engine stops by itself. You want the run() call and the halt() call to be executed by different threads. One way to accomplish this (the right way!) would be to have the event handler that starts the engine create a new
Thread, and start the engine from the run() method of that Thread.
Finally, you have to call halt() on the instance of Rete that's actually running -- not a separate one created for this purpose. That suggests that the Rete object should be held not in a local variable, but in a member variable, where all your code can get access to it.
I'm not trying to be mean, and I hope I don't hurt your feelings, but it really sounds to me as if the problem here is that you don't have much knowledge of
Java itself. I can't really answer your questions well if you don't yet understand the necessary background. JavaRanch is a great place to ask questions about Java -- head over to the Java in General (Intermediate) forum, the Swing/AWT forum, and/or the Threads and Synchronization forum to ask general Java questions that are relevant;. Furthermore, I'd say you need a good Java book or two -- have a look through the
JavaRanch Bunkhouse for our recommendations.