3 * $Id: AnagGUI.java,v 1.1 2001/02/04 19:53:07 mdw Exp $
7 * (c) 2001 Mark Wooding
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Anag: a simple wordgame helper.
14 * Anag is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * Anag is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Anag; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
31 * $Log: AnagGUI.java,v $
32 * Revision 1.1 2001/02/04 19:53:07 mdw
33 * Simple GUI front-end in Java.
37 /*----- Imports -----------------------------------------------------------*/
44 import java.awt.event.*;
46 /*----- Main code ---------------------------------------------------------*/
48 class Whinge extends Frame {
49 public Whinge(String gripe) {
51 GridBagLayout gb = new GridBagLayout();
54 addWindowListener(new WindowAdapter() {
55 public void windowClosing(WindowEvent e) { dispose(); }
58 GridBagConstraints g = new GridBagConstraints();
59 g.gridx = g.gridy = GridBagConstraints.RELATIVE;
60 g.gridwidth = GridBagConstraints.REMAINDER; g.gridheight = 1;
61 g.weightx = g.weighty = 1;
62 g.insets = new Insets(24, 24, 8, 24);
63 Label l = new Label(gripe);
64 add(l); gb.setConstraints(l, g);
66 Button b = new Button("Bummer");
67 b.addActionListener(new ActionListener() {
68 public void actionPerformed(ActionEvent e) { dispose(); }
71 g.insets.top = 0; g.insets.bottom = 24;
72 add(b); gb.setConstraints(l, g);
78 class AnagPanel extends Panel {
82 void splat(String gripe) {
86 void getlist(String tag) {
88 Vector v = new Vector();
92 v.addElement(word.getText());
93 vv = new String[v.size()];
95 Process p = Runtime.getRuntime().exec(vv);
96 LineNumberReader fout =
97 new LineNumberReader(new InputStreamReader(p.getInputStream()));
98 LineNumberReader ferr =
99 new LineNumberReader(new InputStreamReader(p.getErrorStream()));
103 while ((l = fout.readLine()) != null)
105 StringBuffer d = new StringBuffer();
106 while ((l = ferr.readLine()) != null)
107 d.append(l).append("\n");
114 vv = new String[v.size()];
116 for (i = 0; i < vv.length; i++)
119 } catch (IOException e) {
126 GridBagLayout gb = new GridBagLayout();
130 GridBagConstraints g = new GridBagConstraints();
131 g.gridx = g.gridy = GridBagConstraints.RELATIVE;
132 g.gridwidth = g.gridheight = 1;
133 g.weightx = 1; g.weighty = 0;
135 word = new TextField(40);
136 g.fill = GridBagConstraints.HORIZONTAL;
137 g.insets = new Insets(8, 8, 8, 8);
138 add(word); gb.setConstraints(word, g);
140 g.fill = GridBagConstraints.NONE;
141 g.weightx = g.weighty = 0;
143 b = new Button("Anagram");
144 b.addActionListener(new ActionListener() {
145 public void actionPerformed(ActionEvent e) { getlist("-anagram"); }
147 add(b); gb.setConstraints(b, g);
148 b = new Button("Subgram");
149 b.addActionListener(new ActionListener() {
150 public void actionPerformed(ActionEvent e) { getlist("-subgram"); }
152 add(b); gb.setConstraints(b, g);
153 b = new Button("Wildcard");
154 b.addActionListener(new ActionListener() {
155 public void actionPerformed(ActionEvent e) { getlist("-wildcard"); }
157 add(b); gb.setConstraints(b, g);
158 b = new Button("Trackword");
159 b.addActionListener(new ActionListener() {
160 public void actionPerformed(ActionEvent e) { getlist("-trackword"); }
162 g.gridwidth = GridBagConstraints.REMAINDER;
163 add(b); gb.setConstraints(b, g);
165 list = new java.awt.List(20);
166 g.fill = GridBagConstraints.BOTH;
167 g.insets.left = 8; g.insets.top = 0;
169 g.weightx = g.weighty = 1;
170 add(list); gb.setConstraints(list, g);
174 /*----- Program or applet -------------------------------------------------*/
176 public class AnagGUI extends Applet {
177 public static void main(String[] argv) {
178 Frame f = new Frame("Anagram solver");
179 f.addWindowListener(new WindowAdapter() {
180 public void windowClosing(WindowEvent e) { System.exit(0); }
182 AnagPanel p = new AnagPanel();
187 public AnagGUI() { super(); setLayout(new BorderLayout()); }
188 public void init() { add(new AnagPanel()); }
189 public void destroy() { removeAll(); }
192 /*----- That's all, folks -------------------------------------------------*/