DrawingGraphics


The applet's real estate is the area within the border

Source

AnAppletWithGraphics.java:
import java.applet.*;
import java.awt.*;

public class AnAppletWithGraphics extends Applet {
	public void paint(Graphics g) {
		g.drawLine(0, 0, 100, 100);
		g.setColor(Color.green);
		g.drawRect(10, 30, 20, 60);
		g.setColor(new Color(100, 50, 210));
		g.fillOval(20, 10, 15, 30);
		g.setColor(Color.red);
		g.drawString("Hi There!", 25, 55);

	}
}

Description and Objective

The AnAppletWithGraphics class

Notes

Drawing Graphics

This Applet's Behavior

Things to Do

API work Playing with the Applet Place the following applets on the same page:
  1. Code an applet that draws a smiley face
  2. Code an applet that accepts two integer parameters.
    • The first, named quantity (assume it will be no more than 4) determines the number of circles to draw. The circles should be drawn adjacent to each other, touching at the single point.
    • The second parameter is the diameter of each circle.
    • Introduce an init method and some instance variables to hold the values of the parameters
  3. Same as #1, but now, have the face toggle between a smiley and a frown with each invocation of paint