-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMove1.java
More file actions
83 lines (80 loc) · 1.4 KB
/
Copy pathMove1.java
File metadata and controls
83 lines (80 loc) · 1.4 KB
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
package priyanshu;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class Move1 extends Applet implements Runnable,ActionListener
{
Thread t;
int x;
Button b1,b2,b3,b4;
@Override
public void init()
{
setBackground(Color.cyan);
b1=new Button("Life 1");
b2=new Button("Kill 2");
b3=new Button("Pause 3");
b4=new Button("Resume 4");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b1.setFont(new Font("Arial",Font.BOLD,20));
b2.setFont(new Font("Arial",Font.BOLD,20));
b3.setFont(new Font("Arial",Font.BOLD,20));
b4.setFont(new Font("Arial",Font.BOLD,20));
add(b1);
add(b2);
add(b3);
add(b4);
}
@Override
public void actionPerformed(ActionEvent ae)
{
Button bb=(Button)ae.getSource();
if((bb==b1) && (t==null))
{
t=new Thread(this);
t.start();
}
else if((bb==b2) && (t!=null))
{
t.stop();
t=null;
}
else if((bb==b3) && (t!=null))
{
t.suspend();
}
else if((bb==b4) && (t!=null))
{
t.resume();
}
}
@Override
public void run()
{
while(true)
{
for(x=1;x<=getSize().width;x+=20)
{
repaint();
try{
Thread.sleep(200);
}catch(InterruptedException ie)
{
}
}
}
}
@Override
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.fillOval(x,200,80,80);
}
}
/*
<applet code="Move1" width=500 height=500>
</applet>
*/