FileDocCategorySizeDatePackage
MessageApplet.javaAPI DocExample1360Mon Oct 11 15:07:22 BST 1999None

MessageApplet.java

/*
 * This example is from the book "Java Foundation Classes in a Nutshell".
 * Written by David Flanagan. Copyright (c) 1999 by O'Reilly & Associates.  
 * You may distribute this source code for non-commercial purposes only.
 * You may study, modify, and use this example for any purpose, as long as
 * this notice is retained.  Note that this example is provided "as is",
 * WITHOUT WARRANTY of any kind either expressed or implied.
 */

import java.applet.*;
import java.awt.*;

public class MessageApplet extends Applet {
  protected String message;   // The text to display
  protected Font font;        // The font to display it in

  // One-time initialization for the applet
  public void init() {
    message = this.getParameter("message");
    font = new Font("Helvetica", Font.BOLD, 48);
  }

  // Draw the applet whenever necessary.
  public void paint(Graphics g) {
    // The pink oval
    g.setColor(Color.pink);
    g.fillOval(10, 10, 330, 100);

    // The red outline. The browser may not support Java2D, so we
    // try to simulate a 4-pixel wide line by drawing four ovals.
    g.setColor(Color.red);
    g.drawOval(10,10, 330, 100);
    g.drawOval(9, 9, 332, 102);
    g.drawOval(8, 8, 334, 104);
    g.drawOval(7, 7, 336, 106);

    // The text
    g.setColor(Color.black);
    g.setFont(font);
    g.drawString(message, 40, 75);
  }
}