import java.awt.*; public class example3 extends BufferedApplet { int w = 0, h = 0; double cx = 0, cy = 0; double deltaX = 0, deltaY = 0; double time0 = 0, time = 0; Font font = new Font("Helvetica", Font.BOLD, 30); double timePerFrame = 0.01; double elapsed = 0, prevElapsed = 0; public void render(Graphics g) { if (w == 0) { w = bounds().width; h = bounds().height; time0 = System.currentTimeMillis() / 1000.0; cx = w / 2; cy = h; } prevElapsed = elapsed; time = System.currentTimeMillis() / 1000.0; elapsed = (time - time0); if (prevElapsed != 0) { timePerFrame = 0.95 * timePerFrame + 0.05 * (elapsed - prevElapsed); } g.setColor(Color.black); g.fillRect(0, 0, w, h); drawMyCharacter(g, (int)cx, (int)cy); cy += deltaY; if (cy >= h) { cy = h; deltaY = 0; } deltaY += 2 * timePerFrame; animating = true; } void drawMyCharacter(Graphics g, int x, int y) { g.setColor(Color.red); g.fillRect(x - 20, y - 40, 40, 40); g.setColor(Color.black); g.fillRect(x - 10, y - 30, 20, 30); } public boolean mouseUp(Event e, int x, int y) { deltaY = -200 * timePerFrame; return true; } public boolean mouseMove(Event e, int x, int y) { return true; } }