ptg7068951
Completing a Graphical Application 213
you could use LottoMadnessfor lottery contests that generate a wider or
smaller range of values.
The LottoMadnessproject lacks variables used to keep track of things such
as the number of drawings, winning counts, and lotto number text fields.
Instead, the interface stores values and displays them automatically.
To finish the project, reopen LottoMadness.javain NetBeans. You only
need to add six lines to make it work with the LottoEventclass.
First, add a new instance variable to hold a LottoEventobject:
LottoEvent lotto= new LottoEvent(this);
Next, in the LottoMadness()constructor, call the addItemListener()and
addActionListener()methods of each user interface component that can
receive user input:
// Add listeners
quickpick.addItemListener(lotto);
personal.addItemListener(lotto);
stop.addActionListener(lotto);
play.addActionListener(lotto);
reset.addActionListener(lotto);
Listing 15.3 contains the full text of LottoMadness.javaafter you have
made the changes. The lines you added are shaded—the rest is unchanged
from the previous hour.
LISTING 15.3 The Full Text of LottoMadness.java
1: importjava.awt.;
2: importjavax.swing.;
3:
4: public classLottoMadness extendsJFrame {
5: LottoEvent lotto= new LottoEvent(this);
6:
7: // set up row 1
8: JPanel row1= new JPanel();
9: ButtonGroup option= new ButtonGroup();
10: JCheckBox quickpick= new JCheckBox(“Quick Pick”, false);
11: JCheckBox personal= new JCheckBox(“Personal”, true);
12: // set up row 2
13: JPanel row2= new JPanel();
14: JLabel numbersLabel= new JLabel(“Your picks: “, JLabel.RIGHT);
15: JTextField[] numbers= new JTextField[6];
16: JLabel winnersLabel= new JLabel(“Winners: “, JLabel.RIGHT);
17: JTextField[] winners= new JTextField[6];
18: // set up row 3
19: JPanel row3= new JPanel();
20: JButton stop= new JButton(“Stop”);