// file: MyFrame1.java // author: Robert Keller // purpose: Show use of Graphics class for simple unanimated graphics import java.awt.*; // to get awt (abstract window toolkit) public class MyFrame1 extends Frame // Customize Frame class { // test Program public static void main(String[] arg) { MyFrame1 frame = new MyFrame1("My Frame", 50, 50); frame.drawStuff(); } // construct frame with title and position MyFrame1(String title, int x, int y) { setTitle(title); setBackground(Color.white); // set the background color reshape(x, y, 500, 400); // set the location and size setVisible(true); // show the frame toFront(); } // draw items in Graphics specified in argument; called by paint(g) void drawStuff() { Graphics g = getGraphics(); g.setColor(Color.black); // set the color for drawing g.drawRect(50, 50, 400, 300); // draw a rectangle g.fillOval(100, 100, 300, 200); // fill an oval g.setFont(new Font("Times", Font.BOLD, 20)); g.setColor(Color.yellow); g.drawString("Harvey Mudd College", 120, 210); // draw a string } // paint(Graphics) will be called by the system to paint the Frame when // necessary, e.g. when setVisible(true) is called. This call is done // implicitly; we do not see it in the source. // The Graphics of the frame will then be passed as an argument. public void paint(Graphics g) { } }