Difference between revisions of "Graphics2D"

From Progzoo
Jump to: navigation, search
(setColor)
(setColor)
Line 11: Line 11:
 
</question>
 
</question>
  
==setColor==
+
==setColor using predefined colors==
 
The method '''setColor''' determines the color used for following operation (such as fillRect). '''setColor''' takes a color as a parameter.
 
The method '''setColor''' determines the color used for following operation (such as fillRect). '''setColor''' takes a color as a parameter.
 
<question width='100' height='100' className='Raster' imgOut='flag.png'>
 
<question width='100' height='100' className='Raster' imgOut='flag.png'>
Line 23: Line 23:
 
</question>
 
</question>
  
 +
==setColor using custom colors==
 
<question width='100' height='100' className='Raster' imgOut='flag.png'>
 
<question width='100' height='100' className='Raster' imgOut='flag.png'>
 
'''Custom Colors'''
 
'''Custom Colors'''

Revision as of 13:09, 7 September 2008

The Graphics2D class is part of the Java library. It is documented at http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Graphics2D.html

fillRect

The method fillRect(x,y,w,h) takes four parameters x,y (for the top left corner) and w,h for the width and height of the rectangle to be filled.


[Font] [Default] [Show] [Resize] [History] [Profile]

setColor using predefined colors

The method setColor determines the color used for following operation (such as fillRect). setColor takes a color as a parameter.

Named Colors You can use one of the standard colors such as Color.red. Other colors include: black blue cyan darkGray gray green lightGray magenta orange pink red white yellow.


[Font] [Default] [Show] [Resize] [History] [Profile]

setColor using custom colors

Custom Colors You can use a custom color using the constructor new Color(255,0,128) which uses red, green and blue components 255, 0, 128. Each component can be a value from 0 to 255.


[Font] [Default] [Show] [Resize] [History] [Profile]