Java Reference
In-Depth Information
•Method paintComponent can be used to draw graphics in any JComponent component.
•Method paintComponent receives a Graphics object that is passed to the method by the system
when a lightweight Swing component needs to be repainted.
• When an application executes, the application container calls method paintComponent . For
paintComponent to be called again, an event must occur.
•When a JComponent is displayed, its paintComponent method is called.
•Caing method repaint (p. 559) on a component updates the graphics drawn on that component.
Section 13.3 Color Control
• Class Color (p. 559) declares methods and constants for manipulating colors in a Java program.
• Every color is created from a red, a green and a blue component. Together these components are
called RGB values (p. 560). The RGB components specify the amount of red, green and blue in
a color, respectively. The larger the value, the greater the amount of that particular color.
Color methods getRed , getGreen and getBlue (p. 560) return int values from 0 to 255 repre-
senting the amount of red, green and blue, respectively.
Graphics method getColor ( p. 560) returns a Color object with the current drawing color.
Graphics method setColor ( p. 560) sets the current drawing color.
Graphics method fillRect (p. 560) draws a rectangle filled by the Graphics object's current color.
Graphics method drawString (p. 562) draws a String in the current color.
•The JColorChooser GUI component (p. 563) enables application users to select colors.
JColorChooser static method showDialog (p. 564) displays a modal JColorChooser dialog.
Section 13.4 Manipulating Fonts
• Class Font (p. 566) contains methods and constants for manipulating fonts.
• Class Font 's constructor takes three arguments—the font name (p. 567) , font style and font size.
•A Font 's font style can be Font.PLAIN , Font.ITALIC or Font.BOLD (each is a static field of class
Font ). Font styles can be used in combination (e.g., Font.ITALIC + Font.BOLD ).
• The font size is measured in points. A point is 1/72 of an inch.
Graphics method setFont (p. 567) sets the drawing font in which text will be displayed.
Font method getSize ( p. 567) returns the font size in points.
Font method getName ( p. 567) returns the current font name as a string.
Font method getStyle ( p. 569) returns an integer value representing the current Font 's style.
Font method getFamily ( p. 569) returns the name of the font family to which the current font
belongs. The name of the font family is platform specific.
• Class FontMetrics (p. 569) contains methods for obtaining font information.
• Font metrics (p. 569) include height, descent and leading.
Section 13.5 Drawing Lines, Rectangles and Ovals
Graphics methods fillRoundRect (p. 573) and drawRoundRect (p. 573) draw rectangles with
rounded corners.
Graphics methods draw3DRect (p. 575) and fill3DRect (p. 575) draw three-dimensional rect-
angles.
Graphics methods drawOval (p. 575) and fillOval (p. 575) draw ovals.
Search WWH ::




Custom Search