Difference between revisions of "Flags with Rectangles Tutorial"

From Progzoo
Jump to: navigation, search
Line 10: Line 10:
 
Try the program as it is given, then change it so that the green rectangle is 150 wide.<br/>
 
Try the program as it is given, then change it so that the green rectangle is 150 wide.<br/>
 
[[Image:flaglibya.png|border]]<prog lang="java">
 
[[Image:flaglibya.png|border]]<prog lang="java">
static void drawFlag(Graphics g){
+
static void drawFlag(Graphics g)
 +
{
 
   g.setColor(new Color(0,128,0));
 
   g.setColor(new Color(0,128,0));
 
   g.fillRect(0,0,75,100);
 
   g.fillRect(0,0,75,100);
 
}   
 
}   
 
</prog> <answer lang="java">  
 
</prog> <answer lang="java">  
static void drawFlag(Graphics g){
+
static void drawFlag(Graphics g)
 +
{
 
   g.setColor(new Color(0,128,0));
 
   g.setColor(new Color(0,128,0));
 
   g.fillRect(0,0,150,100);
 
   g.fillRect(0,0,150,100);
Line 28: Line 30:
 
The code given draws only one of the three rectangles required, and it is in the wrong place.<br/>
 
The code given draws only one of the three rectangles required, and it is in the wrong place.<br/>
 
[[Image:flag_guide_france.png|border]]<prog lang="java">
 
[[Image:flag_guide_france.png|border]]<prog lang="java">
static void drawFlag(Graphics g){
+
static void drawFlag(Graphics g)
 +
{
 
   g.setColor(Color.blue);
 
   g.setColor(Color.blue);
 
   g.fillRect(100,0,50,100);
 
   g.fillRect(100,0,50,100);
 
}
 
}
 
</prog><answer lang="java">
 
</prog><answer lang="java">
static void drawFlag(Graphics g){
+
static void drawFlag(Graphics g)
 +
{
 
   g.setColor(Color.blue);
 
   g.setColor(Color.blue);
 
   g.fillRect(0,0,50,100);
 
   g.fillRect(0,0,50,100);
Line 51: Line 55:
 
Only one of the three rectangles has been drawn - and that one is in the wrong place.<br/>
 
Only one of the three rectangles has been drawn - and that one is in the wrong place.<br/>
 
[[Image:flaggermany.png|border]] <prog lang="java">
 
[[Image:flaggermany.png|border]] <prog lang="java">
static void drawFlag(Graphics g){
+
static void drawFlag(Graphics g)
 +
{
 
   g.setColor(Color.yellow);
 
   g.setColor(Color.yellow);
 
   g.fillRect(0,0,150,30);
 
   g.fillRect(0,0,150,30);
Line 57: Line 62:
 
</prog>
 
</prog>
 
<answer lang="java">
 
<answer lang="java">
static void drawFlag(Graphics g){
+
static void drawFlag(Graphics g)
 +
{
 
   g.setColor(Color.black);
 
   g.setColor(Color.black);
 
   g.fillRect(0,0,150,30);
 
   g.fillRect(0,0,150,30);
Line 81: Line 87:
 
</hint>
 
</hint>
 
<prog lang="java">
 
<prog lang="java">
static void drawFlag(Graphics2D g){
+
static void drawFlag(Graphics2D g)
 +
{
 
   g.setColor(Color.white);
 
   g.setColor(Color.white);
 
   g.fillRect(0,0,150,100);
 
   g.fillRect(0,0,150,100);
Line 87: Line 94:
 
}
 
}
 
</prog><answer lang="java">
 
</prog><answer lang="java">
static void drawFlag(Graphics2D g){
+
static void drawFlag(Graphics2D g)
 +
{
 
   g.setColor(Color.white);
 
   g.setColor(Color.white);
 
   g.fillRect(0,0,150,100);
 
   g.fillRect(0,0,150,100);

Revision as of 14:30, 26 April 2012

Experiment in interaction

Libya

The flag of Libya is a simple green rectangle.

Try the program as it is given, then change it so that the green rectangle is 150 wide.
Flaglibya.png

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

France

The flag of France is blue, white and red. The code given draws only one of the three rectangles required, and it is in the wrong place.
Flag guide france.png

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

Germany

The flag of Germany is black, red and yellow.

Only one of the three rectangles has been drawn - and that one is in the wrong place.
Flaggermany.png

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

Japan

  • The flag of Japan is a red circle on a white background.
  • The rectangle is 150 by 100.
  • The circle is in position 45,20, width and height are 60,60.
  • The dark lines are NOT part of the flag. They are shown as guides only.

Flagjapan.png


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

Now you can try the Rectangles Quick Quiz Lecture 2 Support