Drawing Applet Code                Peter Komisar



/* The real point of this applet aside from showing how graphics methods are used
    is to show how the arc width and height values are used to create the rounded
    corners. Note how the corners have the shapes corresponding to ovals that would
    be created if these values are used.                                                                   */
 
import java.applet.*;
import java.awt.*;

// <applet code="Drawing.java" width="300" height="260"></applet>

public class Drawing extends Applet{
  public void init (){
    setBackground(new Color(0,0,0));
    setForeground(new Color(255,255,255));
    }

  public void paint(Graphics g){
    g.drawString("A few graphics methods",30,20);
    g.drawLine(30,22,160,22);
    g.drawRect(30,30,240,140);
    g.setColor(Color.pink);
    g.drawOval(40,50,80,20);
    g.drawOval(70,80,30,70);
    g.setColor(new Color(233,255,233));
    g.drawRoundRect(120,50,90,90,80,20); //same as first oval
    g.drawRoundRect(160,70,90,90,30,70); //same as second oval
    g.setColor(Color.yellow);
    g.drawString("Note how the oval size correspond to",30,190);
    g.drawString("the rounded corners of the rectangles",30,210);
    }
  }