import java.awt.*;
import javax.swing.*;
public class FlyBall {
public static void main(String[] args) {
JFrame w = new JFrame();
w.setSize(300, 400);
MyJPanel mj = new MyJPanel();
w.add(mj);
Thread t = new Thread(mj);
t.start();
w.setVisible(true);
}
}
class MyJPanel extends JPanel implements Runnable{
int x=30;
int y=30;
public void paint(Graphics g) {
super.paint(g);
g.fillOval(x, y, 30, 30);
}
public void run() {
while(true) {
y++;
if( y>400 ) {
y=0;
}
try{
Thread.sleep(40);
}catch(Exception e){}
repaint();
}
}
}
以上是代码, super.paint(g); 这条语句在代码中起到什么作用 |
|