-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimate.java
More file actions
49 lines (43 loc) · 1021 Bytes
/
Animate.java
File metadata and controls
49 lines (43 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import javax.swing.*;
import java.awt.*;
public class Animate
{
int x = 1;
int y = 1;
public static void main(String[] args)
{
Animate gui = new Animate();
gui.go();
}
public void go()
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyDrawP drawP = new MyDrawP();
frame.getContentPane().add(drawP);
frame.setSize(500,270);
frame.setVisible(true);
for (int i = 0; i < 124; i++,y++,x+=2)
{
//x++;
drawP.repaint();
try
{
Thread.sleep(50);
}
catch(Exception ex)
{
}
}
}
class MyDrawP extends JPanel
{
public void paintComponent(Graphics g)
{
g.setColor(Color.white);
g.fillRect(0,0,500,250);
g.setColor(Color.blue);
g.fillRect(x,y,500-x*2,250-y*2);
}
}
}