|
In this lab, like the last one, you will run a Java program in order to draw some simple graphics on the computer screen. Unlike the last lab, however, you will write (portions of) the program yourself. And unlike in the last lab, in this one it will be your program which will do the drawing rather than you (with the mouse).
In preparation for (or during) this lab, you should read Chapter 2 of the text; you will in any case want to keep it handy during the lab as a reference.
Note especially the code template in Figure 2.16 on page 72 and the table of methods in Table 2.1 on page 73.
In order to fulfill the assignment, you should write a Java applet which
draws a picture on the screen. Your picture should have at least 3 stick figures
(representing people) and some text (a caption, labels for the figures, slogans,
etc.). Feel free to be as creative as you like with your drawing, but there is
no need to do anything fancy: this is not an art class, just a programming class!
As an example of the sort of drawing which would meet the minimum requirements
(and which conveys a sense of the minimal artistic talent required), consider
the following example:
Remember, your job is to write a program which will draw a scene such as this one,
not to make the drawing yourself with the mouse. This will necessarily limit what
you can do because of the paucity of tools available (if you can get a simple example
working fully, you are of course welcome to explore more the sophisticated options
which are available, but they won't count for extra credit).
For your demo I may ask you to make small modifications to your program, so make
sure everything is working by then and that you understand enough of the process
to be able to "tweak" it. You may want to practice a few such changes before you
commit to a demo.
Since this assignment is an applet, not an application (see the
text or future lectures for details), you will want to select the
"AWT Applet" template when creating your new project. This will
automatically give you a file called "Applet1.java" which you can
open from the "Files" tab of your project window. Modify this code
to include everything in the template on page 72.
Once you get the template code in place, you should be able to
make a window appear. Try this by itself before continuing. Then
maybe add a single drawing command and see how it works. Then add
a few more, etc. By proceeding in a progressive fashion, you will
always have a working program and will spend less time back-tracking
and revising things.
In particular, don't try anything too fancy until you have a program
which meets the minimum requirements set out above. And save a copy
of any working minimal program before you modify it too much.
You can easily write a simple program which will fulfill the problem
description by using a simple sequence of drawing commands and integer
co-ordinates. However, in order to make your program easier to modify
(during demo or for a later assignment), it will behoove you to think
about how you can better capture the "essence" of what your program does.
For example, you might use named variables instead of integer
constants in order to consolidate references to different parts of
the drawing (e.g., central coordinates of one of the figures). (See pages
83-95 for information on how to declare integer variables.)
Another idea along these lines would be to use arithmetic to calculate
certain values based on other ones. For example, you might calculate
the size or position of a "child" figure based on a scaling of an
"adult" figures dimensions.
We will concentrate on these issues of abstraction much more in later
assignments, but it is good for you to at least begin thinking about them
now.
As shown in the template on page 72, your program should always
include at least a simple comment giving authorship and contextual
information (what class is this, what semester, which school, etc.).
To the extent that you do anything non-obvious, you should also add
(short) comments which make your code more understandable (remember,
your programs will be read by non-technical people who will be using
them to assess your writing abilities).
You should have your program complete and ready to go by the time you ask for
a demo. You should also bring a completed demo form (I will pass out final
versions before the due date).
Most of the grade for this assignment will be in getting your program to
compile and run correctly, but some points will also be available for
stylistic issues and for the abstraction ideas mentioned above. I will
talk more about point allocations in lecture or lab.
Basic instructions
Tips and hints
What to expect for your demo