import javax.swing.*; import java.io.*; /** * FrilJavaDemo.java * * Title: Fril - Java noughts and crosses (tic-tac-toe) demo * * Description * Tutorial example of Fril embedded in a java application. * Java is used to handle the user interaction and display the current state of play. * Fril works out the next move and is also used to check whether the game has finished. * As the aim is to illustrate one way of communicating between Fril and Java, the * software does not incorporate large amounts of error checking etc. * The GUI is created and handled in PlayingWindow.java and JButtonSquare.java. * The Fril code is in "noughts5". Note that human takes 'x' and computer takes 'o' in * the game - this is hard-coded in the Fril source and PlayingWindow.java, JButtonSquare.java. * * Note that the high-level interface function "jFrilFindSolution" is used in this code. This * allows a string query of the form (X (move ((...) (...) (...)) X)) to be sent to Fril - syntax is * identical to a fril "wh" query, i.e. the variable or pattern required is the first term in the list * and the remainder of the list is a goal to be executed. * The value returned to java gives the TYPE of the bound variable (JFril.JFRILINT, JFril.JFRILATOM, etc) * and a low-level "jFrilGet..." function can be used to retrieve the value. * * The front end includes debugging features so that Fril queries can be typed into a text area, and output * from Fril and Java can be viewed in other text windows. * * @author T. P. Martin * @date June 2001 * @version 1.0b1 */ public class FrilJavaDemo { static private PlayingWindow theWindow = null; static private JFril theFril; final static int BLANK = -1; final static int HUMAN = -2; final static int COMPUTER = -3; final static int DRAW = -4; public FrilJavaDemo(JFril aFril) { try { // For native Look and Feel, uncomment the following code. /* try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { } */ theWindow = new PlayingWindow(this, aFril); theWindow.initComponents(); theWindow.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } // Main entry point static public void main(String[] args) { int i; JFril aFril = new JFril(); new FrilJavaDemo(aFril); if(theWindow != null) if(aFril.jFrilExecuteFril("load noughts5") == JFril.JFRILSUCCEEDED) theWindow.addJavaText("fril started OK"); else theWindow.addJavaText("Fril couldn't load noughts5"); } }