Java Reference
In-Depth Information
If you need paintComponent to execute (i.e., if you want to update the graphics drawn
on a Swing component), you can call method repaint , which returns void , takes no argu-
ments and is inherited by all JComponent s indirectly from class Component (package
java.awt ).
13.3 Color Control
Class Color declares methods and constants for manipulating colors in a Java program.
The predeclared color constants are summarized in Fig. 13.3, and several color methods
and constructors are summarized in Fig. 13.4. Two of the methods in Fig. 13.4 are Graph-
ics methods that are specific to colors.
Color constant
RGB value
public static final Color RED
255, 0, 0
public static final Color GREEN
0, 255, 0
public static final Color BLUE
0, 0, 255
public static final Color ORANGE
255, 200, 0
public static final Color PINK
255, 175, 175
public static final Color CYAN
0, 255, 255
public static final Color MAGENTA
255, 0, 255
public static final Color YELLOW
255, 255, 0
public static final Color BLACK
0, 0, 0
public static final Color WHITE
255, 255, 255
public static final Color GRAY
128, 128, 128
public static final Color LIGHT_GRAY
192, 192, 192
public static final Color DARK_GRAY
64, 64, 64
Fig. 13.3 | Color constants and their RGB values.
Method
Description
Color constructors and methods
public Color( int r, int g, int b)
Creates a color based on red, green and blue components expressed as integers
from 0 to 255.
public Color( float r, float g, float b)
Creates a color based on red, green and blue components expressed as floating-
point values from 0.0 to 1.0.
public int getRed()
Returns a value between 0 and 255 representing the red content.
Fig. 13.4 | Color methods and color-related Graphics methods. (Part 1 of 2.)
 
 
Search WWH ::




Custom Search