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

(singke) #1
ptg7068951

Completing a Graphical Application 211

94: if ( winText.equals( allPicks[i].getText() ) ) {
95: return true;
96: }
97: }
98: return false;
99: }
100:
101: public voidrun() {
102: Thread thisThread = Thread.currentThread();
103: while(playing== thisThread) {
104: addOneToField(gui.drawings);
105: int draw = Integer.parseInt(gui.drawings.getText());
106: floatnumYears = (float)draw / 104;
107: gui.years.setText(“” + numYears);
108:
109: int matches = 0;
110: for (int i = 0; i < 6; i++) {
111: int ball;
112: do {
113: ball = (int) Math.floor(Math.random() * 50 + 1);
114: } while(numberGone(ball, gui.winners, i));
115: gui.winners[i].setText(“” + ball);
116: if (matchedOne(gui.winners[i], gui.numbers)) {
117: matches++;
118: }
119: }
120: switch(matches) {
121: case3:
122: addOneToField(gui.got3);
123: break;
124: case4:
125: addOneToField(gui.got4);
126: break;
127: case5:
128: addOneToField(gui.got5);
129: break;
130: case6:
131: addOneToField(gui.got6);
132: gui.stop.setEnabled(false);
133: gui.play.setEnabled(true);
134: playing= null;
135: }
136: try {
137: Thread.sleep(100);
138: } catch(InterruptedException e) {
139: // do nothing
140: }
141: }
142: }
143: }


LISTING 15.2 Continued

Free download pdf