Java Reference
In-Depth Information
Figure 11•1. A sampling of graphics primitives
Example 11•1: GraphicsSampler.java (continued)
Color fill, outline, textcolor; // The various colors we use
Font font;
// The font we use for text
FontMetrics metrics;
// Information about font size
Image image, background;
// Some images we draw with
// This method is called when the applet is first created.
// It performs initialization, such as creating the resources
// (graphics attribute values) used by the paint() method.
public void init() {
// Initialize color resources. Note the use of the Color() constructor
// and the use of pre-defined color constants.
fill = new Color(200, 200, 200); // Equal red, green, and blue == gray
outline = Color.blue;
// Same as new Color(0, 0, 255)
textcolor = Color.red;
// Same as new Color(255, 0, 0)
// Create a font for use in the paint() method. Get its metrics, too.
font = new Font("sansserif", Font.BOLD, 14);
metrics = this.getFontMetrics(font);
Search WWH ::




Custom Search