Richard, Kevin R. wrote:
I'm planning on using a defglobal variable to reflect the state of a
checkbox in the UI for my application. The value of this variable,
therefore will be set and modified in Java. Looking at the Jess API, I
don't see any means of changing the value of a Defglobal object once it
has been set. The value of this variable will influence many of the
rules that I'll be running.
You do not want to use a defglobal for this. You have several options,
including:
a) Make your object a standard Java Bean(1), call definstance() on your
Rete object passing it the bean instance(s), and have your Swing/Java
code update the bean to reflect the state of your UI.
Your rules can then directly pattern match against the bean's
properties. When those properties change (via PropertyChangeEvents), the
Rete object will automagically evaluate your rules to reflect the new
state of your UI.
b) Create your UI objects using Java and/or Jess code and then implement
the Swing/AWT callback methods directly using Jess deffunctions to trap
UI based events. In these deffunction handlers, you can update the Rete
with facts or other objects as needed. Again, your rules can react the
the changes made by the deffunctions.
To do this easily see the recently added (implement) function ;-D
In either of these cases, you will need to consider which thread your
rules will be firing on. IMHO, you should have a dedicated thread call
Rete#runUntilHalt() so that all you rule firings will be done on a
single thread and your UI/handler code won't be stuck spending time
firing rules instead of responding to the user.
There are a number of other usage patterns you could consider but these
are fairly typical and well documented in the manual and elsewhere.
alan
(1) Primarily, implement getters/setters + PropertyChangeEvents. See the
Jess manual and the book Jess In Action for more details and potential
hazards.
--------------------------------------------------------------------
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]
--------------------------------------------------------------------