// SimpleGraphicsApp.java // (c) 1997 Kim Tabtiang & Kim Bruce import java.applet.Applet; import graphics.*; import java.awt.*; /** class for illustrating use of graphics package */ public class SimpleGraphicsApp extends Applet { // fields Rect r; // Rectangle to be drawn Line l; // Line to be drawn diagonally on screen Oval ovFrame, // Oval to be drawn in framed (outline) form ovFill; // Oval to be drawn filled in Arc cArc; // Arc to be drawn on screen DrawableString cdStr, // Blue string to be drawn cdStr2; // Boldface, green string to be drawn // methods /** Set up objects to be drawn on screen */ public void init() { // Note all of this could have been combined w/ variable declarations. r = new Rect(50,100,100,100,Color.green); // Create green rectangle l = new Line(0,0,500,500,Color.white); // Create line ovFrame = new Oval(50, 100, 100, 100); // Create oval ovFill = new Oval(250, 200, 250, 100, Rect.FILL); // Create a solid oval cArc = new Arc(200,200,100,150,90,180,Color.red); // Create red arc cdStr = new DrawableString("The End is Come", 50, 200, Color.blue); // Create blue string cdStr2 = new DrawableString("KIM", 200,200, new Font("TimesRoman", Font.BOLD, 20),Color.green); // Create bold green string } /** Draw all the shapes when screen is painted. */ public void paint(Graphics g) { r.render(this); // Draw all shapes initialized in init() l.render(this); // Component is this applet ovFrame.render(this); ovFill.render(this); cArc.render(this); cdStr.render(this); cdStr2.render(this); // Declare and create new cyan RoundRect at (250,250) RoundRect rndRect = new RoundRect(250,250, 10, 10, 2, 2, Color.cyan); for (int i=1; i<=10; i++) // Create 10 nested rectangles { rndRect.render(this); // Draw rndRect and then increase dimensions rndRect.resize(10*(i+1),10*(i+1)); } System.out.println("Repainted applet"); } }