import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Movement extends Applet implements ActionListener
{
Frame f=new Frame();
Panel p=new Panel();
Button b1=new Button("重新开始");
Button b2=new Button("暂停");
Button b3=new Button("继续");
public Movement()
{
p.add(b1);p.add(b2);p.add(b3);
f.add(p,"South");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
f.pack();
f.setVisible(true);
}
Thread runner;
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
i=1;
}
if(e.getSource()==b2)
{
runner.suspend();
}
if(e.getSource()==b3)
{
runner.resume();
}
}
int i=0;
public void paint(Graphics g)
{
i+=10;
if(i<490)
{
g.setColor(Color.red);
g.fillOval(i,50,10,10);
try
{
runner.sleep(500);
}
catch(InterruptedException e){}
}
repaint();
}
public static void main(String[] args)
{
new Movement();
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="000000">
<center>
<applet
code = "Movement.java"
width = "500"
height = "300"
>
</applet>
</center>
</body>
</html>