import java.awt.*; public class example2 extends BufferedApplet { int BR = 20; int w = 0, h = 0; int mx = 0, my = 0; double bx = 0, by = 0; double time0 = 0, time = 0; Font font = new Font("Helvetica", Font.BOLD, 30); double deltaX = 0.0; double deltaY = 2.0; int level = 0; public void render(Graphics g) { if (w == 0) { w = bounds().width; h = bounds().height; time0 = System.currentTimeMillis() / 1000.0; } time = System.currentTimeMillis() / 1000.0; double elapsed = (time - time0); g.setColor(Color.black); g.fillRect(0, 0, w, h); g.setColor(Color.white); g.fillRect(mx - 25, h - 50, 50, 10); g.setColor(Color.red); g.fillOval((int)bx - BR, (int)by - BR, 2*BR, 2*BR); g.setColor(Color.white); g.fillOval((int)bx + BR/4, (int)by - 2*BR/3, 3*BR/5, 3*BR/5); if (bx >= BR && bx + deltaX < BR) deltaX = -deltaX; if (bx < w-BR && bx + deltaX >= w-BR) deltaX = -deltaX; if (bx >= mx - 25 && bx < mx + 25 && by + BR >= h - 50) deltaY = -2; bx += deltaX; by += deltaY; deltaY += 0.01; animating = true; } public boolean mouseUp(Event e, int x, int y) { bx = x; by = 0; deltaX = 4 * (-1.0 + 2 * (time % 1.0)); deltaY = 2; return true; } public boolean mouseMove(Event e, int x, int y) { mx = x; my = y; return true; } }