The set Paint method of the Graphics2D class lets you select a color that is used for all subsequent drawing operations on the graphics context. For example:
You can fill the interiors of closed shapes (such as rectangles or ellipses) with a color.Simply call fill instead of draw:
To draw in multiple colors, you select a color, draw or fill, then select another color, and draw or fill again.
You define colors with the Color class. The java .awt .Colorclass offers predefined constants for the following 13 standard colors:
BLACK, BLUE, CYAN, DARK_GRAY, GRAY, GREEN, LIGHT_GRAY, MAGENTA, ORANGE, PINK, RED, WHITE, YELLOW
NOTE: Before Java SE 1.4, color constant names were lowercase, such as Color.red. This is odd because the standard coding convention is to write constants in uppercase. You can
now write the standard color names in uppercase or, for backward compatibility, in lowercase. You can specify a custom color by creating a Color object by its red, green, and blue components. Using a scale of 0–255 (that is, one byte) for the redness, blueness, and greenness, call the Color constructor like this:
NOTE: In addition to solid colors, you can select more complex “paint” settings, such as varying hues or images. See the Advanced AWT chapter in Volume II for more details. If you use a Graphics object instead of a Graphics2D object, you need to use the setColormethod to set colors.
To set the background color, you use the set Background method of the Component class, an ancestor of JComponent.
There is also a set Foreground method. It specifies the default color that is used for drawing on the component.
TIP: The brighter() and darker() methods of the Color class produce, as their names suggest,either brighter or darker versions of the current color. Using the brighter method is also a good way to highlight an item. Actually, brighter() is just a little bit brighter. To make a color really stand out, apply it three times: c.brighter().brighter().brighter().
Java gives you predefined names for many more colors in its SystemColorclass. The constants in this class encapsulate the colors used for various elements of the user’s system.For example,
sets the background color of the component to the default used by all windows on the user’s desktop. (The background is filled in whenever the window is repainted.) Using the colors in the System Color class is particularly useful when you want to draw user interface elements so that the colors match those already found on the user’s desktop. Table below lists the system color names and their meanings.
Core Java Related Interview Questions
|J2EE Interview Questions||Core Java Interview Questions|
|JDBC Interview Questions||JSP Interview Questions|
|Android Interview Questions||JavaServer Faces (JSF) Interview Questions|
|Java collections framework Interview Questions||Java 8 Interview Questions|
|Java Collections Interview Questions||Java Exception Handling Interview Questions|
|Java Concurrency Interview Questions||Java Serialization Interview Questions|
|Java Programmer Interview Questions||Java Inheritance Interview Questions|
|Java IO Interview Questions||Object Oriented Programming in PHP Interview Questions|
Core Java Tutorial
An Introduction To Java
The Java Programming Environment
Fundamental Programming Structures In Java
Objects And Classes
Interfaces And Inner Classes
User Interface Components With Swing
Deploying Applications And Applets
Exceptions, Logging, Assertions, And Debugging
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.