Java Reference
In-Depth Information
// g.drawRect (0, 0, d.width, d.height);
int x = getSize().width / 2;
int y = getScrY();
g.drawLine (x-5, y-1, x+5, y-1);
g.drawLine (x-5, y-1, x, y - 10);
g.drawLine (x+5, y-1, x, y - 10);
if (thrust > 10) {
g.drawLine (x-3, y+1, x-3, (int) (y + 1 + thrust /
20));
g.drawLine (x+3, y+1, x+3, (int) (y + 1 + thrust /
20));
g.drawLine (x, y+1, x, (int) (y + 1 + thrust / 15));
}
oldY = y;
oldThrust = thrust;
}
public Dimension getPreferredSize() {
return new Dimension (50, 100);
}
public Dimension getMinimumSize() {
return new Dimension (20, 50);
}
int getScrY() {
int scrH = getSize().height;
return scrH - (int) (height * scrH / START_HEIGHT);
}
public void check() {
if (thrust != oldThrust || oldY != getScrY())
repaint();
}
}
class ScreenManager implements Runnable {
public String milliToStr (long milli) {
return (milli / 1000) + "." + Math.abs ((milli % 1000) /
100);
}
public void run() {
if (height <= 0)
heightDisplay.setText
(velocity <= MAX_VELOCITY
? "Landed"
: "Crashed!");
else
heightDisplay.setText (milliToStr (height));
Search WWH ::




Custom Search