-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplet.java
More file actions
59 lines (56 loc) · 920 Bytes
/
applet.java
File metadata and controls
59 lines (56 loc) · 920 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
50
51
52
53
54
55
56
57
58
59
import java.awt.*;
import java.applet.*;
public class slip3_java2 extends Applet implements Runnable
{
int y=400;
Thread th=null;
public void paint(Graphics g)
{
int r=(int)(Math.random()*255);
int gr=(int)(Math.random()*255);
int b=(int)(Math.random()*255);
Color c=new Color(r,gr,b);
g.setColor(c);
g.fillOval(200,y,100,100);
}
public void init()
{
th=new Thread(this);
th.start();
}
public void run()
{
try
{
int i=1;
while(true)
{
if(y>0 && i==1)
{
y=y-5;
repaint();
th.sleep(100);
}
else if(y<=0 && i==1)
{
i=2;
}
else if(y<=400 && i==2)
{
y=y+5;
repaint();
th.sleep(100);
}
else
{
i=1;
}
}
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
/<applet code="slip3_java2.class" width=400 height=400></applet>/