Difference between revisions of "Graphics2D"

From Progzoo
Jump to navigation Jump to search
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<shell lang="java" className="Flag" import="shells.xml#raster"/>
 
<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
 +
==drawOval==
 +
<question width='100' height='100' className='Raster' imgOut='flag.png'>
 +
The method '''drawOval(x,y,w,h)''' takes four parameters x,y (for the top left corner of the rectangle that contains the oval) and w,h for the width and height of the oval to be drawn. The kind of line is determined by you most recent setLine statement.
 +
<prog lang='java'>static void drawFlag(Graphics2D g){
 +
  g.setColor(Color.black);
 +
  g.drawOval(10,10,30,60);
 +
}</prog>
 +
</question>
 +
 +
==drawRect==
 +
<question width='100' height='100' className='Raster' imgOut='flag.png'>
 +
The method '''drawRect(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 drawn. The kind of line is determined by you most recent setLine statement.
 +
<prog lang='java'>static void drawFlag(Graphics2D g){
 +
  g.setColor(Color.black);
 +
  g.drawRect(10,10,30,30);
 +
}</prog>
 +
</question>
 +
 +
==fillOval==
 +
<question width='100' height='100' className='Raster' imgOut='flag.png'>
 +
The method '''fillOval(x,y,w,h)''' takes four parameters x,y (for the top left corner of the rectangle that contains the oval) and w,h for the width and height of the oval to be filled.
 +
<prog lang='java'>static void drawFlag(Graphics2D g){
 +
  g.setColor(Color.black);
 +
  g.fillOval(10,10,30,60);
 +
}</prog>
 +
</question>
 +
 
==fillRect==
 
==fillRect==
 +
<question width='100' height='100' className='Raster' imgOut='flag.png'>
 
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 width='100' height='100' className='Raster' imgOut='flag.png'>
 
 
<prog lang='java'>static void drawFlag(Graphics2D g){
 
<prog lang='java'>static void drawFlag(Graphics2D g){
 
   g.setColor(Color.black);
 
   g.setColor(Color.black);
Line 12: Line 39:
 
==setColor==
 
==setColor==
 
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'>
 
'''Named Colors'''
 
'''Named Colors'''
 
 
You can use one of the standard colors such as '''Color.red'''.
 
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.
 
Other colors include: black blue cyan darkGray gray green lightGray magenta orange pink red white yellow.
 +
<prog lang='java'>static void drawFlag(Graphics2D g){
 +
  g.setColor(Color.red);
 +
  g.fillRect(10,10,30,30);
 +
}</prog>
 +
</question>
  
 +
 +
<question width='100' height='100' className='Raster' imgOut='flag.png'>
 
'''Custom Colors'''
 
'''Custom Colors'''
You can use one of the standard 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.
+
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.
<question width='100' height='100' className='Raster' imgOut='flag.png'>
 
 
<prog lang='java'>static void drawFlag(Graphics2D g){
 
<prog lang='java'>static void drawFlag(Graphics2D g){
   g.setColor(Color.red);
+
   g.setColor(new Color(255,0,128));
 
   g.fillRect(10,10,30,30);
 
   g.fillRect(10,10,30,30);
 
}</prog>
 
}</prog>
 
</question>
 
</question>

Latest revision as of 19:20, 8 November 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

drawOval

The method drawOval(x,y,w,h) takes four parameters x,y (for the top left corner of the rectangle that contains the oval) and w,h for the width and height of the oval to be drawn. The kind of line is determined by you most recent setLine statement.


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

drawRect

The method drawRect(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 drawn. The kind of line is determined by you most recent setLine statement.


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

fillOval

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


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

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

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]


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]