import java.awt.*; import java.applet.*; /* <applet code=BallAnim width=800 height=600> </applet> */ //画一个正方形和一个移动的球,实现了Runnable接口。 public class BallAnim extends Applet implements Runnable Thread animThread; int ballX=100;//球的x坐标 int bally;10;//球的Y坐标 int ballDirection=0;//球移动的方向标志:0表示从上向下移动,1表示从下向上移动 public void init() super.setBackground(Color.blue); public void start() if (animThread !=null) animThread = new Thread(this); animThread.start(); public void stop() animThread.stop(); animThread = null; // 实现Runnable接 public void run() Thread.currentThread().setPriority(Thread. NORM_PRIORITY);//设置线呈优先级 NORM_PRIORITY while (true) moveBall(); try Thread.sleep(100); // 休眠0.1秒 catch (Exception sleepProblem) // This applet ignores any exceptions if it has a problem sleeping. // Maybe it should take Sominex