// draw items in Graphics in Frame;
called by paint()
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)
{
drawStuff();
}
}