/* This program will only work with figure.class */ import java.awt.*; import java.awt.event.*; import java.awt.Graphics; import javax.swing.*; public class figs extends JFrame { public Graphics brush; public Graphics display; private Image canvas; // off-screen graphics buffer private Color bkcolor = Color.white; public void paint(Graphics g) {} // overrides auto-update public static void main(String[] args) // needed for application { figs session = new figs(); session.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }); session.init(); } public void init() { setBounds(0,0,800,600); show(); canvas = createImage(800,600); brush = canvas.getGraphics(); display = this.getGraphics(); brush.setColor(bkcolor); // clear brush.fillRect(0,0,800,600); // with black background brush.setColor(Color.green); // animate(); } // init public int randint(int min, int max) { return (int) (Math.random() * (max-min+1) + min); } public void clearbuffer() { Color old; old = brush.getColor(); brush.setColor(bkcolor); // clear brush.fillRect(0,0,800,600); // with black background brush.setColor(old); // restores color } // clearbuffer public void nextframe(int delay) // delay in ms { try { Thread.sleep(delay); } catch (InterruptedException IE) {} display.drawImage(canvas,0,0,null); // draws to screen clearbuffer(); } // nextframe with ms delay public void animate() { figure fig1 = new figure(400,300,this); /* **** YOUR CODE GOES HERE ... **** */ } // animate } // class figs