I'm writing an application in Java using JPL provided by SWI-Prolog to call Prolog from Java.
I'm using Eclipse as the IDE. I don't know how to start this example I found online:
Here the java code:
package prolog;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import jpl.Atom;
import jpl.Compound;
import jpl.Variable;
import jpl.Term;
import jpl.Query;
import jpl.JPL;
@SuppressWarnings({ "unchecked", "deprecation", "serial" })
public class JavaProlog extends JFrame {
JButton startButton = new JButton("Start");
JTextArea textArea = new JTextArea("A Diagnostic Expert System \n" +
"for respiratory diseases and lung.");
/**
*/
JavaProlog(){
Container cp=getContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation (200,200);
setSize (300,200);
setLayout (new FlowLayout());
startButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
startDiagnose();
}
});
cp.add(textArea);
cp.add(startButton);
setVisible(true);
}
private void startDiagnose(){
Term consult_arg[] = {
new Atom( "C://Users//i_vista//workspace//mdc.pl" )
};
Query consult_query =
new Query(
"consult",
consult_arg );
boolean consulted = consult_query.query();
if ( !consulted ){
System.err.println( "Consult failed" );
System.exit( 1 );
}
}
public static void main( String argv[] ){
JPL.init();
JavaProlog jpTest = new JavaProlog();
}
If I run the Prolog program directly from Prolog it works fine and the same when I call it from the Java application.
I can also see the output in the Eclipse console and I can reply to the questions.
But I would like to build a Java UI for the interaction between the user and the system but I don't know how to take the code from Prolog in Java and put it in the UI.
For example how can I capture input from the Java UI and pass this to the Prolog code?