import java.awt.*; public class moving extends BufferedApplet { int w = 0, h = 0; double time0 = 0; // IF YOU'RE REALLY AMBITIOUS, YOU CAN COUNT SECONDS BY: double getTime() { return System.currentTimeMillis() / 1000.0; } public void render(Graphics g) { if (w == 0) { w = bounds().width; h = bounds().height; time0 = getTime(); } g.setColor(Color.white); g.fillRect(0,0,w,h); g.setColor(Color.black); int c = (int)(100 * Math.cos(2 * getTime())); int s = (int)(100 * Math.cos(getTime())); g.drawRect(100 + c, 100 + s, 50, 50); //System.err.println( (getTime() - time0) ); animating = true; } }