[java]代码库
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Panel;
public class pp {
public static void main(String args[]) {
Frame w = new Frame();
w.setSize(300, 400);
MyPanel mp = new MyPanel();
w.add(mp);
Thread t = new Thread(mp);
t.start();
w.show();
}
}
class MyPanel extends Panel implements Runnable {
int x = 30;
int y = 30;
public void paint(Graphics g) {
/*
* g.fillOval(30,30,20,20); int x=30; int y=30; while(true){
*
* y++; }
*/
g.fillOval(x, y, 20, 30);
}
public void run() {
while (true) {
y++;
if (y > 400) {
y = 0;
}
try{
Thread.sleep(40);
}catch(Exception e){};
repaint();
}
}
}
[代码运行效果截图]