/* * EventTest Java Program */ import java.applet.*; import java.awt.*; public class EventTest extends Applet { int maxObj = 3; /* max object number */ mPoint object[]; /* objecct array */ Image img; int current = -1, hit = -1; int xofs = 0, yofs = 0; public void init() { /* initial object array */ setBackground(Color.black); setForeground(Color.white); object = new mPoint[maxObj]; /* initial a rectangle */ object[0] = new mRectangle(10, 10, 100, 100); object[0].setColor(Color.red); /* initial a circle */ object[1] = new mCircle(200, 10, 100, 100); object[1].setColor(Color.red); /* initial a triangle */ object[2] = new mTriangle(10, 200, 100, 100); object[2].setColor(Color.red); img = createImage(size().width, size().height); } /* this method will be called to repond a repaint */ public void paint(Graphics g) { update(g);} /* this method will be called to repond a disclosure */ public void update(Graphics g) { /* Get Off Screen Graphics Context */ Graphics og = img.getGraphics(); /* fill background */ og.setColor(getBackground()); og.fillRect(1, 1, size().width-2, size().height-2); /* draw boundry */ og.setColor(getForeground()); og.drawRect(0, 0, size().width-1, size().height-1); /* draw objects */ for (int i=0; i