Help is available for each task.
Task 1
The first step is to create a working directory somewhere on your filesystem, hereafter referred to as workingdir.
To avoid confusion, create a new directory instead of using an existing directory that has existing/other files.
Task 2
Next, create the directory stickfigure (all lowercase characters) directly under workingdir.
To avoid subsequent confusion, create and verify that the directory name contains all lowercase characters. The directory stickfigure will house the StickFigure-related classes, which belong to the stickfigure package. The package and directory names must match exactly, and in some Bean-aware environments, they must be lowercase.
Task 3
Next, (1) save all the skeleton files, except the *.java files, within workingdir and (2) save the *.java skeleton files within stickfigure, that is, within workingdir/stickfigure.
After compilation, the directory stickfigure will house the StickFigure-related classes. The package and directory names must match exactly, and in some Bean-aware environments, they must be lowercase.
Task 4
The next, and primary, task is to add surprise functionality to the StickFigure Bean. You must implement the addSurprise() and removeSurprise() control methods, as well as the boolean variable surprised (note the "d" ending, for the variable only), which is manipulated by these two methods. This variable should be initialized to false.
The surprise state logic is that if a StickFigure Bean instance is in the surprised state, the drawing operations will draw the mouth differently. Note that the control methods must invoke repaint() after setting the surprised variable. Do not substitute a setSurprise() method for these two control methods--the surprise state is not a property.
The logic for handling the surprised state is already incorporated into the Bean's drawing operations--for this reason, you must use the variable name surprised. The point of this Magercise is to add the control methods for externally manipulating the state of surprise, and then connect these methods to external controls (command buttons) from a development tool.
This is a fairly simple task, requiring approximately nine or ten lines of code. Do not tamper with the drawing-related methods. The drawing methods already test the surprised variable to draw the mouth appropriately.
Task 5
Compile all JavaTM source files, *.java, from workingdir by including the stickfigure directory in the path specification.
From a command window type (excluding the prompt):
C:\workingdir>javac stickfigure\*.java [DOS] or
/workingdir>javac stickfigure/*.java [UNIX]
An alternative approach, if you prefer graphical tools, is to build the stickfigure package within your Java development environment.
Verify that StickFigure.class, StickFigureEvent.class, and StickFigureListener.class exist within the stickfigure directory by typing (excluding the prompt):
C:\workingdir>dir stickfigure
10/14/98 03:10p <DIR> .
10/14/98 03:10p <DIR> ..
10/14/98 03:10p 7,082 StickFigure.class
10/14/98 02:39p 8,176 StickFigure.java
10/14/98 03:10p 956 StickFigureEvent.class
10/01/98 09:25p 831 StickFigureEvent.java
10/14/98 03:10p 298 StickFigureListener.class
10/01/98 09:27p 191 StickFigureListener.java
8 File(s) 17,534 bytes
Task 6
Build StickFigure.jar from workingdir by executing the file MakeStickFigureJar.bat (Windows) or MakeStickFigureJar.sh (UNIX).
From a command window type (excluding the prompt):
C:\workingdir>MakeStickFigureJar
jar cvmf stickfigure.txt StickFigure.jar
stickfigure\*.class
adding: stickfigure/StickFigure.class (in=7082)
(out=3195) (deflated 54%)
adding: stickfigure/StickFigureEvent.class (in=956)
(out=497) (deflated 48%)
adding: stickfigure/StickFigureListener.class (in=298)
(out=214) (deflated 28%)
Task 7
Next, load the StickFigure Bean into the BeanBox (or a comparable tool) using "LoadJar..." from the BeanBox "File" menu.
Start up the BeanBox, select "LoadJar..." from the BeanBox "File" menu, and then navigate to your workingdir and open/load StickFigure.jar.
Task 8
The next task is to configure surprise and no-surprise controls for a StickFigure Bean. First, select and place a StickFigure and two OurButton Beans on the worksheet.
Task 9
Next, change the label for either OurButton Bean to "Surprise Me" and connect its action-performed functionality to the StickFigure Bean's add-surprise functionality.
First, select an OurButton instance. Then,
- Change the label to "Surprise Me" via the property sheet
- Select the "Edit" menu
- Select the "Events" submenu
- Select the "action" submenu
- Select the "actionPerformed" menu item
These operations enable a rubberband-like red line that you drag to the target, in this case, the stick figure Bean:
- Attach the red line to the stick figure Bean by selecting it
- Select the "addSurprise" functionality from the dialog's list
- Select the "OK" button
Task 10
Next, change the label for the other OurButton Bean to "No More Surprises" and connect its action-performed functionality to the StickFigure Bean's remove-surprise functionality. After setting up these connections, you will be able to use the two command buttons to control the stick figure's state of surprise.
First, select the other OurButton instance. Then,
- Change the label to "No More Surprises" via the property sheet
- Select the "Edit" menu
- Select the "Events" submenu
- Select the "action" submenu
- Select the "actionPerformed" menu item
These operations enable a rubberband-like red line that you drag to the target, in this case, the stick figure Bean:
- Attach the red line to the stick figure Bean by selecting it
- Select the "removeSurprise" functionality from the dialog's list
- Select the "OK" button
Copyright © 1998-1999
MageLang Institute.
All Rights Reserved.