/* * Test Java Program */ import java.applet.*; import java.awt.*; public class Test extends Applet implements Runnable { int maxObj = 6; /* max object number */ mPoint object[]; /* objecct array */ Thread thread; public void init() { /* initial object array */ object = new mPoint[maxObj]; /* initial a rectangle */ object[0] = new mRectangle(10, 10, 80, 80); object[0].setDelta(1, 1); object[0].setColor(Color.red); /* initial a circle */ object[1] = new mCircle(200, 10, 100, 100); object[1].setDelta(-1, 1); object[1].setColor(Color.blue); /* initial a triangle */ object[2] = new mTriangle(10, 200, 100, 100); object[2].setDelta(-1, 1); object[2].setColor(Color.green); object[3] = new mTriangle(100, 200, 100, 100); object[3].setDelta(1, -1); object[3].setColor(Color.yellow); object[4] = new mCircle(30, 10, 80, 100); object[4].setDelta(1, 1); object[4].setColor(Color.white); object[5] = new mRectangle(160, 60, 100, 150); object[5].setDelta(-1, -1); object[5].setColor(Color.red); } /* start a new thread */ public void start() { if (thread == null) { thread = new Thread(this); thread.start(); } } /* stop the thread */ public void stop() { if (thread != null) { thread.stop(); thread = null; } } /* keep moving and redraw the objects */ public void run() { while (thread != null) { try {thread.sleep(20);} catch (InterruptedException e){} repaint(); } } /* this method will be called to respond repaint() */ public void update(Graphics g) { /* check boundry and move object */ g.setXORMode(Color.black); for (int i=0; i