public class Car {
public static final int BLOCK_SIZE = 20;
private Graphics g;
int wide = Car.BLOCK_SIZE;
int high = Car.BLOCK_SIZE;
public void draw(int row, int col, Graphics g) {
Color c = g.getColor();
g.setColor(Color.BLACK);
g.fillRect( row, col, wide, high);
g.setColor(c);
}
}
public class Road extends Frame implements Runnable{
private int row = 500;
private int col = 300;
public Road() {
init();
}
public void init(){
setSize(600,600);
setLocation(300,100);
myEvent();
setVisible(true);
}
private void myEvent(){
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public void paint(Graphics g){
Color c = g.getColor();
g.setColor(Color.GRAY);
car.draw(row, col, g);
g.setColor(c);
}
public void run() {
while(true){
row--;
repaint();
}
}
}
public class MainClass {
public static void main(String[] args) {
Road r = new Road();
Thread thread = new Thread(r);
thread.start();
}
}
怎么实现一个长方形的移动?
|