Difference between revisions of "Graphics2D"

From Progzoo
Jump to: navigation, search
Line 1: Line 1:
<shell lang="java" className="Flag" import="shells.xml#raster" width='100' height='100'/>
+
<shell lang="java" className="Flag" import="shells.xml#raster"/>
 
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
 
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
 
==setColor and fillRect==
 
==setColor and fillRect==
Line 7: Line 7:
  
 
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.
 
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.
<question>
+
<question width='100' height='100'>
 
<prog lang='java'>static void drawFlag(Graphics2D g){
 
<prog lang='java'>static void drawFlag(Graphics2D g){
 
   g.setColor(Color.red);
 
   g.setColor(Color.red);

Revision as of 12:48, 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

setColor and fillRect

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

You can use one of the stadard colors (such as Color.red) or you can use a custom color using the constructor new Color(10,20,30) which uses red, green and blue components 10, 20, 30. Each component can be a value from 0 to 255.

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]