import SkipBoWrapper; import java.lang.*; import java.awt.*; /* Creates an frame with input fields and one small response out field. Its purpose is to get the player information for the start of the game. Once the player chooses to start a game, the window closes itself. */ public class InputFrame extends Frame { Font f = new Font("TimesRoman",Font.BOLD,16); TextField inputfield; TextField name1; TextField name2; TextField store_size; TextField out; Button startbutton; SkipBoWrapper parent; public InputFrame (SkipBoWrapper up_one_level) { super("Game Setup"); this.parent = up_one_level; //sets the attributes of the frame this.setLayout(new FlowLayout()); this.setFont(f); this.setBackground(Color.blue); this.setForeground(Color.yellow); //prompt for the size of the store stacks this.add(new Label(" Enter size of store stacks", Label.LEFT)); store_size = new TextField (40); store_size.setBackground(Color.white); store_size.setForeground(Color.black); this.add(store_size); //prompt for the first player's name this.add(new Label(" Enter player1 name", Label.LEFT)); name1 = new TextField (40); name1.setBackground(Color.white); name1.setForeground(Color.black); this.add(name1); //prompt for the second player's name this.add(new Label(" Enter player2 name", Label.LEFT)); name2 = new TextField (40); name2.setBackground(Color.white); name2.setForeground(Color.black); this.add(name2); //add a text area in which to print error messages out = new TextField (75); out.setEditable(false); this.add(out); //add start and close buttons startbutton = new Button("Start Game"); startbutton.setBackground(Color.lightGray); this.add(startbutton); Button closebutton = new Button("Nevermind"); closebutton.setBackground(Color.lightGray); this.add(closebutton); this.resize(630,300); } public boolean action (Event evt, Object what) /* clicking on the close button simply hides the window. The start button serves several purposes: it checks that a valid integer is input and that the integer is between 1 and 20. If the integer is OK then calls the parent applet to start a game with the storesize and names provided by the user. If the integer is not valid then it prints an error message in the output field and clears the storesize input field text. */ { String label = (String)what; String first = null; String second = null; if (label.equals ("Nevermind")) { if (this.isShowing()){ this.hide(); this.dispose(); return true; } } else if (label.equals ("Start Game")) { int storesize = 0; String str1; try { str1 = store_size.getText(); Integer size = new Integer (str1); storesize = size.parseInt(str1); if (0 < storesize && storesize <= 20) { first = name1.getText(); second = name2.getText(); parent.startGame(storesize, first, second); this.hide(); this.dispose(); } else { store_size.setText (""); name1.setText (""); name2.setText (""); out.setText (" store size must be between 1 and 20"); } }catch (NumberFormatException e) { System.out.println ("1 " + e.toString()); store_size.setText (""); name1.setText (""); name2.setText (""); out.setText (" store must be an integer between 1 and 20"); } return true; } return false; } }