chiark / gitweb /
Simple GUI front-end in Java.
authormdw <mdw>
Sun, 4 Feb 2001 19:53:07 +0000 (19:53 +0000)
committermdw <mdw>
Sun, 4 Feb 2001 19:53:07 +0000 (19:53 +0000)
AnagGUI.java [new file with mode: 0644]
Makefile.am

diff --git a/AnagGUI.java b/AnagGUI.java
new file mode 100644 (file)
index 0000000..01f91ee
--- /dev/null
@@ -0,0 +1,192 @@
+/* -*-java-*-
+ *
+ * $Id: AnagGUI.java,v 1.1 2001/02/04 19:53:07 mdw Exp $
+ *
+ * Front-end GUI
+ *
+ * (c) 2001 Mark Wooding
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of Anag: a simple wordgame helper.
+ *
+ * Anag is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * Anag is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Anag; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: AnagGUI.java,v $
+ * Revision 1.1  2001/02/04 19:53:07  mdw
+ * Simple GUI front-end in Java.
+ *
+ */
+
+/*----- Imports -----------------------------------------------------------*/
+
+import java.lang.*;
+import java.util.*;
+import java.io.*;
+import java.awt.*;
+import java.applet.*;
+import java.awt.event.*;
+
+/*----- Main code ---------------------------------------------------------*/
+
+class Whinge extends Frame {
+  public Whinge(String gripe) {
+    super("Error!");
+    GridBagLayout gb = new GridBagLayout();
+    setLayout(gb);
+
+    addWindowListener(new WindowAdapter() {
+        public void windowClosing(WindowEvent e) { dispose(); }
+    });
+
+    GridBagConstraints g = new GridBagConstraints();
+    g.gridx = g.gridy = GridBagConstraints.RELATIVE;
+    g.gridwidth = GridBagConstraints.REMAINDER; g.gridheight = 1;
+    g.weightx = g.weighty = 1;
+    g.insets = new Insets(24, 24, 8, 24);
+    Label l = new Label(gripe);
+    add(l); gb.setConstraints(l, g);
+
+    Button b = new Button("Bummer");
+    b.addActionListener(new ActionListener() {
+        public void actionPerformed(ActionEvent e) { dispose(); }
+    });
+    g.weighty = 0;
+    g.insets.top = 0; g.insets.bottom = 24;
+    add(b); gb.setConstraints(l, g);
+    pack();
+    show();    
+  }
+}
+
+class AnagPanel extends Panel {
+  TextField word;
+  java.awt.List list;
+
+  void splat(String gripe) {
+    new Whinge(gripe);
+  }
+
+  void getlist(String tag) {
+    try {
+       Vector v = new Vector();
+       String[] vv;
+       v.addElement("anag");
+       v.addElement(tag);
+       v.addElement(word.getText());
+       vv = new String[v.size()];
+       v.copyInto(vv);
+       Process p = Runtime.getRuntime().exec(vv);
+       LineNumberReader fout =
+         new LineNumberReader(new InputStreamReader(p.getInputStream()));
+       LineNumberReader ferr =
+         new LineNumberReader(new InputStreamReader(p.getErrorStream()));
+
+       String l;
+       v = new Vector();
+       while ((l = fout.readLine()) != null)
+         v.addElement(l);
+       StringBuffer d = new StringBuffer();
+       while ((l = ferr.readLine()) != null)
+         d.append(l).append("\n");
+       l = d.toString();
+       if (l.length() > 0)
+         splat(l);
+       else {
+         list.removeAll();
+         int i;
+         vv = new String[v.size()];
+         v.copyInto(vv);
+         for (i = 0; i < vv.length; i++)
+           list.add(vv[i]);
+       }
+    } catch (IOException e) {
+       splat(e.toString());
+    }
+  }
+
+  public AnagPanel() {
+    super();
+    GridBagLayout gb = new GridBagLayout();
+    setLayout(gb);
+    Button b;
+
+    GridBagConstraints g = new GridBagConstraints();
+    g.gridx = g.gridy = GridBagConstraints.RELATIVE;
+    g.gridwidth = g.gridheight = 1;
+    g.weightx = 1; g.weighty = 0;
+
+    word = new TextField(40);
+    g.fill = GridBagConstraints.HORIZONTAL;
+    g.insets = new Insets(8, 8, 8, 8);
+    add(word); gb.setConstraints(word, g);
+
+    g.fill = GridBagConstraints.NONE;
+    g.weightx = g.weighty = 0;
+    g.insets.left = 0;
+    b = new Button("Anagram");
+    b.addActionListener(new ActionListener() {
+       public void actionPerformed(ActionEvent e) { getlist("-anagram"); }
+    });
+    add(b); gb.setConstraints(b, g);
+    b = new Button("Subgram");
+    b.addActionListener(new ActionListener() {
+       public void actionPerformed(ActionEvent e) { getlist("-subgram"); }
+    });
+    add(b); gb.setConstraints(b, g);
+    b = new Button("Wildcard");
+    b.addActionListener(new ActionListener() {
+       public void actionPerformed(ActionEvent e) { getlist("-wildcard"); }
+    });
+    add(b); gb.setConstraints(b, g);
+    b = new Button("Trackword");
+    b.addActionListener(new ActionListener() {
+       public void actionPerformed(ActionEvent e) { getlist("-trackword"); }
+    });
+    g.gridwidth = GridBagConstraints.REMAINDER;
+    add(b); gb.setConstraints(b, g);
+
+    list = new java.awt.List(20);
+    g.fill = GridBagConstraints.BOTH;
+    g.insets.left = 8; g.insets.top = 0;
+    g.gridwidth = 5;
+    g.weightx = g.weighty = 1;
+    add(list); gb.setConstraints(list, g);
+  }
+}
+
+/*----- Program or applet -------------------------------------------------*/
+
+public class AnagGUI extends Applet {
+  public static void main(String[] argv) {
+    Frame f = new Frame("Anagram solver");
+    f.addWindowListener(new WindowAdapter() {
+       public void windowClosing(WindowEvent e) { System.exit(0); }
+    });
+    AnagPanel p = new AnagPanel();
+    f.add(p);
+    f.pack();
+    f.show();
+  }
+  public AnagGUI() { super(); setLayout(new BorderLayout()); }
+  public void init() { add(new AnagPanel()); }
+  public void destroy() { removeAll(); }
+};
+
+/*----- That's all, folks -------------------------------------------------*/
index 620b1cc62ba366e438d8ad663b5d8fe90358a24c..8fbe74492bd80626204fce331c5cd6ec5aba7824 100644 (file)
@@ -1,6 +1,6 @@
 ## -*-makefile-*-
 ##
-## $Id: Makefile.am,v 1.1 2001/02/04 17:14:42 mdw Exp $
+## $Id: Makefile.am,v 1.2 2001/02/04 19:53:07 mdw Exp $
 ##
 ## Makefile for Anag
 ##
 ##----- Revision history ----------------------------------------------------
 ##
 ## $Log: Makefile.am,v $
+## Revision 1.2  2001/02/04 19:53:07  mdw
+## Simple GUI front-end in Java.
+##
 ## Revision 1.1  2001/02/04 17:14:42  mdw
 ## Initial checkin
 ##
 
 AUTOMAKE_OPTIONS = foreign
+SUFFIXES = .java .class
+JAVAC = javac
+.java.class:; $(JAVAC) -d . $<
+
 bin_PROGRAMS = anag
 anag_SOURCES = anag.c anag.h wildcard.c anagram.c trackword.c util.c
 
+all: anag.jar
+anag.jar: AnagGUI.class
+       jar cf anag.jar *.class
+AnagGUI.class: AnagGUI.java
+
+EXTRA_DIST = AnagGUI.java
+CLEANFILES = *.class
+
 ##----- That's all, folks ---------------------------------------------------