1 import java.awt.*
;
2 import java.awt.event.*
;
3 import javax.swing.*
;
4
5 public class Animate {
6 int x=1
;
7 int y=1
;
8 public static void main(String[] args){
9 Animate gui=
new Animate();
10 gui.go();
11 }
12 public void go(){
13 JFrame frame=
new JFrame();
14 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
15 MyDrawP drawP=
new MyDrawP();
16 frame.getContentPane().add(drawP);
17 frame.setSize(500,270
);
18 frame.setVisible(
true);
19 for(
int i=0;i<124;
i++,x++,y++){//这样也可以啊、必须的。
20 x++
;
21 drawP.repaint();
22 try{
23 Thread.sleep(50
);
24 }
catch(Exception ex){}
25 }
26 }
27
28 class MyDrawP
extends JPanel{
29 public void paintComponent(Graphics g){
30 g.setColor(Color.white);//忘记了要先弄成白板了。
31 g.fillRect(0, 0, 500, 250);//忘记了要先弄成白板了。
32 g.setColor(Color.blue);
33 g.fillRect(x, y, 500-x*2, 250-y*2
);
34
35 }
36 }
37 }
转载于:https://www.cnblogs.com/meihao1989/p/3246035.html