展开全部
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JFrame;
public class JoinDemo extends JFrame {
public static void main(String[] args) {
new JoinDemo();
}
private int x = 100, y = 100, r = 100;
public JoinDemo() {
this.setTitle("小图形");
this.setSize(800, 600);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
new UpdateThread().start();
}
public void paint(Graphics g) {
Image image = createImage(getWidth(), getHeight());
Graphics gg = image.getGraphics();
bufferedPaint(gg);
gg.dispose();
g.drawImage(image, 0, 0, null);
}
private void bufferedPaint(Graphics gg) {
gg.fillOval(x, y, r, r);
}
class UpdateThread extends Thread {
public void run() {
for (int j = 0; j <= 240; j++) {
y++;
repaint();
sleep(10);
}
}
private void sleep(int millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
说明:
第一:存为JoinDemo.java
第二:加入了一个缓冲,62616964757a686964616fe4b893e5b19e31333332616464以免画面闪烁。