Java Reference
In-Depth Information
if (keyMajor != -1) {
String all = keys [keyMajor];
keySelect = all.substring (0, keyMinor) + "[" + all.charAt
(keyMinor)
+ "]" + all.substring (keyMinor+1);
}
g.drawString ("Feed: " + needed + " " + keySelect, 0,
getHeight()/2, Graphics.BOTTOM|Graphics.HCENTER);
g.drawString ("Score: "+javagochi.score, 0,
-getHeight()/2, Graphics.TOP|Graphics.HCENTER);
Figure 3.20 shows the Javagochi being fed with vitamins. The complete source code is contained in
Listing 3.2 .
Figure 3.20. A Javagochi being fed with vitamins.
Listing 3.2 Javagochi.java —The Complete Javagochi Sample Source Code
import java.util.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
class Consumption extends TimerTask {
Javagochi javagochi;
public Consumption (Javagochi javagochi) {
this.javagochi = javagochi;
}
public void run() {
javagochi.transform (-1 - javagochi.score/100 );
}
}
class KeyConfirmer extends TimerTask {
Face face;
public KeyConfirmer (Face face) {
this.face = face;
}
public void run() {
face.keyConfirmed();
}
}
 
 
 
Search WWH ::




Custom Search