Chapter 1 - Graphical Interface
2. Drawing Shapes and using colors
| /*
Applet will paint special shapes and use colors and fonts Only new methods are explained */ import java.awt.*;
public class DrawExample extends Applet
// Specify variables that will be needed
everywhere, anytime here
// The colors you will use
public void init()
// Standard colors can be named like this
// lesser known colors can be made with
R(ed)G(reen)B(lue).
bgColor = Color.blue; // this will set the backgroundcolor of
the applet
} public void stop()
// now lets draw things on screen
// Now we tell g to change the color
// This will draw a rectangle (xco,yco,xwidth,height);
// This will fill a rectangle
// change colors again g.setColor(weirdColor); // a circle (int x, int y, int width, int
height,int startAngle, int arcAngle);
g.fillArc(120,120,60,60,0,360); g.setColor(Color.yellow); // Draw a line (int x1, int y1, int x2, int y2) g.drawLine(140,140,160,160); // reset the color to the standard color
for the next time the applets paints
g.setColor(Color.black); } } // that's some basic drawing.
|