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

(singke) #1
ptg7068951

Completing a Graphical Application 209

You can use the next statement to retrieve the value of the JTextField
object got3:


String got3value = gui.got3.getText();


Listing 15.2 contains the full text of the LottoEventclass. Create a new
empty Java file called LottoEventin NetBeans to hold the source code.


LISTING 15.2 The Full Text of LottoEvent.java
1: importjavax.swing.;
2: importjava.awt.event.
;
3:
4: public classLottoEvent implementsItemListener, ActionListener,
5: Runnable {
6:
7: LottoMadness gui;
8: Thread playing;
9:
10: publicLottoEvent(LottoMadness in) {
11: gui = in;
12: }
13:
14: public voidactionPerformed(ActionEvent event) {
15: String command = event.getActionCommand();
16: if (command.equals(“Play”)) {
17: startPlaying();
18: }
19: if (command.equals(“Stop”)) {
20: stopPlaying();
21: }
22: if (command.equals(“Reset”)) {
23: clearAllFields();
24: }
25: }
26:
27: voidstartPlaying() {
28: playing= new Thread(this);
29: playing.start();
30: gui.play.setEnabled(false);
31: gui.stop.setEnabled(true);
32: gui.reset.setEnabled(false);
33: gui.quickpick.setEnabled(false);
34: gui.personal.setEnabled(false);
35: }
36:
37: voidstopPlaying() {
38: gui.stop.setEnabled(false);
39: gui.play.setEnabled(true);
40: gui.reset.setEnabled(true);
41: gui.quickpick.setEnabled(true);
42: gui.personal.setEnabled(true);

Free download pdf