-
Notifications
You must be signed in to change notification settings - Fork 0
/
app5.java
86 lines (79 loc) · 1.34 KB
/
app5.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
<applet code="app5" height="400" width="400">
</applet>
*/
import java.applet.*;
import java.awt.*;
public class app5 extends Applet
{
int x=165;
int y=0;
int flag=0;
int R;
int G;
int B;
public void paint(Graphics g)
{
g.fillOval(x,y,70,70);
Color c1=new Color(R,G,B);
if(flag==0&&x==0&&y==165)
{
flag=1;
R=(int)(Math.random()*255);
G=(int)(Math.random()*255);
B=(int)(Math.random()*255);
}
else if(flag==1&&x==165&y==330)
{
flag=2;
R=(int)(Math.random()*255);
G=(int)(Math.random()*255);
B=(int)(Math.random()*255);
}
else if(flag==2&&x==330&&y==165)
{
flag=3;
R=(int)(Math.random()*255);
G=(int)(Math.random()*255);
B=(int)(Math.random()*255);
}
else if(flag==3&&x==165&y==0)
{
flag=0;
R=(int)(Math.random()*255);
G=(int)(Math.random()*255);
B=(int)(Math.random()*255);
}
else if(flag==0)
{
x--;
y++;
setForeground(c1);
}
else if(flag==1)
{
x++;
y++;
setForeground(c1);
}
else if(flag==2)
{
x++;
y--;
setForeground(c1);
}
else if(flag==3)
{
x--;
y--;
setForeground(c1);
}
try
{
Thread.sleep(5);
}
catch(Exception e)
{}
repaint();
}
}