Java Reference
In-Depth Information
if(colorA.getRGB() == colorB.getRGB())
// Do something....
This compares the two integer RGB values for equality.
System Colors
The package
java.awt
defines the class
SystemColor
as a subclass of the
Color
class. The
SystemColor
class encapsulates the standard system colors used for displaying various components.
The class contains definitions for 24
public
final
static
variables of type
SystemColor
that
specify the standard system colors used by the operating system for a range of GUI components. For
example, the system colors for a window are referenced by:
WINDOW
Defines the background color for a window.
WINDOW
_
TEXT
Defines the text color for a window.
WINDOW
_
BORDER
Defines the border color for a window.
You can find the others covering colors used for menus, captions, controls, and so on, if you need them,
by looking at the documentation for the
SystemColor
class.
If you want to compare a
SystemColor
value with a
Color
object you have created, then you must
use the
getRGB()
method in the comparison. This is because the
SystemColor
class stores the colors
internally in a way that makes use of the fields it inherits from the
Color
class differently from a
normal
Color
object. For example, to see whether
colorA
corresponds to the system background
color for a window you would write:
if(colorA.getRGB() == SystemColor.WINDOW.getRGB())
// colorA is the window background color...
Creating Cursors
An object of the
Cursor
class represents a mouse cursor. The
Cursor
class contains a range of
final
static
constants that specify standard cursor types. You use these to select or create a particular
cursor. The standard cursor types are:
DEFAULT
_
CURSOR
N
_
RESIZE
_
CURSOR
NE
_
RESIZE
_
CURSOR
CROSSHAIR
_
CURSOR
S
_
RESIZE
_
CURSOR
NW
_
RESIZE
_
CURSOR
WAIT
_
CURSOR
E
_
RESIZE
_
CURSOR
SE
_
RESIZE
_
CURSOR
TEXT
_
CURSOR
W
_
RESIZE
_
CURSOR
SW
_
RESIZE
_
CURSOR
HAND
_
CURSOR
MOVE
_
CURSOR
The resize cursors are the ones you see when resizing a window by dragging its boundaries. Note that
these are not like the
Color
constants, which are
Color
objects - these constants are of type
int
, not
type
Cursor
, and are intended to be used as arguments to a constructor.