// file: MyFrame1Applet.java // author: Robert Keller // purpose: Applet version of MyFrame1 import java.applet.*; import java.awt.*; // to get awt (abstract window toolkit) public class MyFrame1Applet extends Applet { // init is called from the outside to initialize the Applet public void init() { setup("My Frame", 50, 50); } // setup frame with title and position void setup(String title, int x, int y) { setBackground(Color.white); // set the background color reshape(x, y, 500, 400); // set the location and size setVisible(true); // show the frame } // draw items in Graphics specified in argument; called by paint(g) void drawStuff() { Graphics g = getGraphics(); // get Graphics from Frame 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", 115, 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. // It is also called when the window is opened or moved. // The Graphics of the frame will then be passed as an argument. public void paint(Graphics g) { drawStuff(); } }