views:

258

answers:

0

I'm implementing a software by jpl provided by swi-prolog for calling prolog from java. I'm using Eclipse as IDE. I don't know how to start this example very useful for my purposes that I found on line with other prolog files.

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 file from Prolog (consult *.pl in swi prolog and the program starts with the questions that it makes to the user) they work very well. The same when I call them from the program java. I can see the output in the console of Eclipse and I can replyn to the questions and I ca arrive to the end of the programm. But I would like to build some java gui 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 gui. For example how can I reply to the first question from a gui java and communicate the reply to the prolog program?

Have you any suggestions for me, please?

Thanks