 




|
|
Drawing a Stick Figure
Using the Graphics methods, draw
a stick figure.
|
An OS/2 C version of this Magercise exists in this directory.
Note that the behavior of the C program may not be the same as the Magercise -- it is
presented here for comparision against the Java application you will write in this
Magercise. One of the major differences is that the C version does not support
layout managers, so resizing a window will not resize the contents of that window.
|
Work Location
Perform all work for this magercise in VisualAge project MageLang Magercises, package magercises.drawing.
If this project does not appear in your Workspace add it from the repository (if it exists there) or create a new project using this name.
Tasks
Perform the following tasks:
Create a new class called StickyBoy, StickyGirl or (
StickyPerson, if you prefer). Make it a subclass of java.awt.Canvas,
select "Write code for this class", and have it import java.awt.*.
Draw the following elements:
filled rectangle 52,52,46,74
line 76,126,43,190
line 76,126,107,190
line 99,58,134,30
line 52,58,35,115
oval 26,114,12,12
oval 134,20,12,12
oval 63,27,27,25
rectangle 36,190,16,8
rectangle 99,190,16,9
string "Stick Boy" @ 55,218
Draw the filled rectangle in blue via setColor(Color.blue);
and draw everything else in black; see Color. The oval and rectangle
coordinates are upper-left corner followed by width, height.
Create a new Applet (visually) called Drawing.
Add two StickyBoy beans to the new applet.
Save your applet and run it!
The task numbers above are linked to the
step-by-step help page. Also available
is a complete solution to the
problem, and expected behavior,
to demonstrate it.
|