import java.awt.*; import java.util.*; public class GameAdder extends Dialog { private GameControl gc; private TextField tf; private Label status; private Button b; GameAdder(GameControl g) { super(g,"Add Game",true); gc = g; tf = new TextField(3); tf.setText("6"); tf.selectAll(); resize(200,100); setLayout(new BorderLayout()); add("North",new Label("Maximum number of players allowed? ")); Panel p1 = new Panel(); p1.setLayout(new BorderLayout()); p1.add("West",new Label("Max Players:")); p1.add("East",b = new Button("Ok")); p1.add("Center",tf); add("Center",p1); add("South",status = new Label("Allowable values are from 2 - 6")); pack(); show(); } int toInt(String s) { int num; try { num = (new Integer(s)).intValue(); } catch (Exception e) { num = 0; } return num; } public boolean action(Event evt, Object arg) { if(evt.target instanceof TextField && ((TextField)evt.target) == tf) { if(arg instanceof String) { int maxplayers = toInt((String) arg); if(maxplayers < 2 || maxplayers > 6) { status.setText("Enter a number between 2 and 6!"); tf.selectAll(); return true; } status.setText("Thank you!"); gc.sendMessage("CREATE\t"+maxplayers); ((TextField)evt.target).setText(""); destroy(); return true; } } else if(evt.target instanceof Button && ((Button)evt.target) == b){ postEvent(new Event(tf,Event.ACTION_EVENT,tf.getText())); return true; } return super.action(evt,arg); } public void destroy() { hide(); dispose(); } }