Objektorientierte Programmierung WS 2013/2014 - Datei BallWorld.java
//
// the Ball World game
// Described in Chapter 5 of
// Understanding Object-Oriented Programming with Java
// by Timothy A Budd
// Published by Addison-Wesley
//
import java.awt.*;
public class BallWorld extends Frame {
public static void main(String[] args) {
BallWorld world = new BallWorld(Color.red);
world.setVisible(true);
}
private static final int FrameWidth = 300;
private static final int FrameHeight = 200;
private Ball aBall;
private int counter = 0;
private BallWorld(Color ballColor) {
setSize(FrameWidth, FrameHeight);
setTitle("Ball World");
aBall = new Ball(10, 15, 5);
aBall.setColor(ballColor);
aBall.setMotion(3.0, 6.0);
}
public void paint(Graphics g) {
aBall.paint(g);
aBall.move();
if ((aBall.x() < 0) || (aBall.x() > FrameWidth)) {
aBall.setMotion(-aBall.xMotion(), aBall.yMotion());
}
if ((aBall.y() < 0) || (aBall.y() > FrameHeight)) {
aBall.setMotion(aBall.xMotion(), -aBall.yMotion());
}
counter = counter + 1;
if (counter < 77) {
repaint();
} else {
System.exit(0);
}
try {
Thread.currentThread().sleep(154);
} catch (InterruptedException e) {}
}
}
Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 05.11.2013


