// file: testGraphics1.java // author: Robert Keller // purpose: Show use of Graphics class for simple unanimated graphics import java.awt.*; // to get awt (abstract window toolkit) class testGraphics1 extends Frame // needed to allow over-ride of paint { // consider this to be magic for now // paint(Graphics) will be called by the system to paint the Frame when // necessary. At that time, the Graphics of the frame will be passed as // an argument. public void paint(Graphics g) { g.setColor(Color.black); // set the color for drawing g.drawRect(50, 50, 400, 300); // draw a rectangle g.setColor(Color.blue); g.fillOval(100, 100, 300, 200); // fill an oval g.setFont(new Font("Times", Font.BOLD, 28)); g.setColor(Color.yellow); g.drawString("Harvey Mudd College", 140, 210); // draw a string } public static void main(String[] arg) { testGraphics1 frame = new testGraphics1(); // create the frame frame.setBackground(Color.white); // set the background color frame.reshape(50, 50, 500, 400); // set the location and size frame.show(); // show the frame } // (paint will be called) } // Other times when paint might be called: // If the frame were covered by another frame, then exposed. // If the frame is resized by the user. // If the frame were iconified, then uniconified, by the user. // If the frame is moved.