• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Embedding Jess in Java

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am developping a prototype to help evaluate social projects within specific criteria.
I would like to have here a specific simple example on how to take a value from a text field in a Jframe from java and to pass it to Jess and the opposite way.
The examples i found are not complete and did not get the whole story about I/O routers ....
I need help plz.
Felicity
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Felicity,

Welcome to JavaRanch!

I/O routers are really not the best way to connect a GUI to Jess. They're good for sending printed output to a JTextArea, and connecting a text component to a read-eval loop like the Jess> prompt. But for general programming, it's better to use another mechanism like fetch() and store(), as documented here.

The important thing to remember when you're integrating Jess and Java is that they're not two independent things, running in parallel, waiting for messages from eachother. If main() is written in Java, then no Jess code runs unless you invoke Jess somehow; so sending data to Jess means calling store() to put the information into Jess, and then invoking some Jess code to fetch the value and do something with it. Likewise, from Jess, you use (store) to save some data, and then either invoke a Java method to deal with it, or perhaps simply return from Jess to give control back to Java.

The book "Jess in Action" (see my signature below) spends three chapters on a Swing example, so that's a good resource too.
 
Felicity Parker
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay! thx a lot!
But then again, if I want to put what i retrieved from Jess into a jFrame in a java based GUI, how to do it?
Is it possible to have more than only one TextField to read from and more than a TextArea to write in?
What i would like to do is to have severals frames with in each one several textfields who contavins future facts for my jess programme...
How to design all that?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The same way as if this were any other Java Swing program: the event handlers for the various components would manipulate Jess in some way.

For example, the actionPerformed() method of a JButton's ActionListener might read the values of several JTextFields, construct an object based on those values, call Rete.definstance() to add that object to Jess's working memory, then call Rete.run() to let Jess fire some rules (although this last would best be done in a separately-spawned Thread.) The rules, in turn, could compute some value and use (store) to store the value for later retrieval. Your Java code could then use Rete.fetch() to get the stored value and store that result in a JTextArea.

This is just one scenario out of an infinite range of possibilities. If you want a detailed example with lots of annotated code and explanation, then you'll find one in my book.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic