import java.awt.*; public class example1 extends BufferedApplet { int w = 0, h = 0; int count = 0; int mx = 0, my = 0; Color darkRed = new Color(128, 0, 0); int X[] = new int[20]; int Y[] = new int[20]; long time0; public void render(Graphics g) { if (w == 0) { w = bounds().width; h = bounds().height; time0 = System.currentTimeMillis(); } g.setColor(Color.black); g.fillRect(0, 0, w, h); long time = System.currentTimeMillis(); double elapsed = (time - time0) / 1000.0; count = (int)(30 * elapsed); int dx = (int)(100 * Math.cos(0.1 * count)); int dy = (int)(100 * Math.sin(0.1 * count)); int dw = (int)(10 * Math.cos(0.2 * count)); int dh = (int)(10 * Math.sin(0.3 * count)); g.setColor(Color.white); g.drawLine(200 + dx, 200 + dy, 200 - dx, 200 - dy); drawMyShape(g, 200 + dx, 200 + dy, 50 + dw, 50 + dh); drawMyShape(g, 200 - dx, 200 - dy, 50 + dw, 50 + dh); g.setColor(Color.blue); X[0] = 100 + dx; X[1] = 200; X[2] = 100; Y[0] = 200; Y[1] = 200 + dy; Y[2] = 100; g.fillPolygon(X, Y, 3); g.setColor(Color.green); drawMyShape(g, mx, my, 30, 30); animating = true; } void drawMyShape(Graphics g, int x, int y, int w, int h) { g.setColor(darkRed); g.fillOval(x - w/2, y - h/2, w, h); g.setColor(Color.white); g.drawOval(x - w/2, y - h/2, w, h); } public boolean mouseMove(Event e, int x, int y) { mx = x; my = y; return true; } }