Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

214 HOUR 15:Responding to User Input


21: JButton play= new JButton(“Play”);
22: JButton reset= new JButton(“Reset”);
23: // set up row 4
24: JPanel row4= new JPanel();
25: JLabel got3Label= new JLabel(“3 of 6: “, JLabel.RIGHT);
26: JTextField got3= new JTextField(“0”);
27: JLabel got4Label= new JLabel(“4 of 6: “, JLabel.RIGHT);
28: JTextField got4= new JTextField(“0”);
29: JLabel got5Label= new JLabel(“5 of 6: “, JLabel.RIGHT);
30: JTextField got5= new JTextField(“0”);
31: JLabel got6Label= new JLabel(“6 of 6: “, JLabel.RIGHT);
32: JTextField got6= new JTextField(“0”, 10);
33: JLabel drawingsLabel= new JLabel(“Drawings: “, JLabel.RIGHT);
34: JTextField drawings= new JTextField(“0”);
35: JLabel yearsLabel= new JLabel(“Years: “, JLabel.RIGHT);
36: JTextField years= new JTextField(“0”);
37:
38: public LottoMadness() {
39: super(“Lotto Madness”);
40: setLookAndFeel();
41: setSize(550, 270);
42: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
43: GridLayout layout = new GridLayout(5, 1, 10, 10);
44: setLayout(layout);
45:
46: // Add listeners
47: quickpick.addItemListener(lotto);
48: personal.addItemListener(lotto);
49: stop.addActionListener(lotto);
50: play.addActionListener(lotto);
51: reset.addActionListener(lotto);
52:
53: FlowLayout layout1 = new FlowLayout(FlowLayout.CENTER,
54: 10, 10);
55: option.add(quickpick);
56: option.add(personal);
57: row1.setLayout(layout1);
58: row1.add(quickpick);
59: row1.add(personal);
60: add(row1);
61:
62: GridLayout layout2 = new GridLayout(2, 7, 10, 10);
63: row2.setLayout(layout2);
64: row2.add(numbersLabel);
65: for (int i = 0; i < 6; i++) {
66: numbers[i] = new JTextField();
67: row2.add(numbers[i]);
68: }
69: row2.add(winnersLabel);
70: for (int i = 0; i < 6; i++) {
71: winners[i] = new JTextField();
72: winners[i].setEditable(false);

LISTING 15.3 Continued
Free download pdf