CSC 171 LAB #8
FALL 2001
GOAL:
1.
Become
familiar with data hiding in objects
2.
Learn
a little more about graphics functions
TASKS:
1.
Implement
a post-modern art drawing Applet
BACKGROUND:
Create a drawing applet that
randomly draws lines, rectangles and ovals. For this purpose, create a set of
“smart” shape classes: MyLine, MyRect, and MyOval. Objects of these classes
know how to draw themselves if provided with a Graphics object.
The data for class MyLine should
include x1, y1, x2, and y2 coordinates. Method drawLine of the class Graphics
will connect the two points supplied with a line. The data for classes MyRect
and MyOval should include an upper-left x-coordinate value, an upper-left
y-coordinate value, a width (must be non-negative) and a height (must be
non-negative). All data in each class must be private. All three classes must
contain a variable of type Color for the drawing color.
Each class must define at least
the following public methods
Your applet should include three
arrays of shapes (one array of MyLine[], one array of MyOval[], and one array
of MyRect[]) each array must be at least 5 items long. Fill the arrays with
random shapes of the appropriate type. In your applet’s paint methods should
loop through the arrays and invoke each shape’s draw method with a call like
mylines[i].draw(g).
STEPS:
1.
You
can use swing or the vanilla awt – your choice.
2.
Start
by writing the simple MyLine class – make certain it compiles.
3.
In
a separate file, in the same directory, write your html file and your applet
class with an init() method and a paint() method. The applet should have an
instance variable of type MyLine. The variable should be instantiated with
“hand chosen” values in the init method. The paint method should call the
variable’s paint method. shape (e.g. if you have an instance variable x1, you
should have a method setX1).
4.
Add
a Button with an actionListener to your applet. When the button is clicked
reset the values in the variable to new random variables. The end points must
fall within the applet window.
1.
The
size of the area you have to draw on is set in the html file by the width and
height parameters of the <applet> tag. The applet methods
1.
int
appWidth =
Integer.parseInt(getParameter("width"));
2.
int
appHeight = Integer.parseInt(getParameter("height"));
2.
Re-read
section 6.8 (pp 261-265) of D&D on how to generate random values within
specific values.
3.
Color
variables are built with the new Color(int red, int green, int blue)
constructor. The values of red, green, and blue must be in the range
0<=value<=255
5.
Repeat
step 3 for the MyRect and MyOval classes.
6.
Add
variables for a rectangle and an oval to your applet. Be sure to randomly reset
them in your actionlistener.
7.
At
this point you should have 4 class files in your directory. Use the Java
archive utility to combine them into a single archive file. Re-read section 8.8.1
(pp 409-410) on the procedure to do this.
8.
In
the end, your applet should look something like this: Clothed Person Ascending in an Elevator - by T.F. Pawlicki, 2001 but it is ok if it does not look exactly
like it, because, like, we are all individuals, man, and our personal artistic
expression is a unique part of our own individual self-expression.
9.
When
you get the paper ready call your lab TA over and demo the program for her/him.
Give the paper to your TA. This completes the hand in process. The deadline is
one week – no late assignments accepted.
10.
The
demo must run from your troi account – not the local machine. All that should
be in the directory is your html file and your jar file.
11.
Stop
and think for a moment about your own personal artistic expression. How does it
relate to you as an individual, you as a technologist? Is computer art really
art at all? Is it merely “technology”? Is not the medium of any artistic
expression based on some technique or technology? Are dead oil, brushes, and
canvas - or cold marble and chisels - more “artistic” than dynamic bits and
glowing phosphor? What is the relationship of the artist to technology? At what
point does “technique” become “art”? Does computer art speak to the modern
world? Does it speak to the post-modern world? Does it speak to the
post-post-modern world? If it does speak, what does it say? Does it say what it
should say, or something else? If it does not speak, could it? What is the role
of randomness in art? In what sense does an artist “control” expression and in
what sense is an artist “controlled by” expression? What is the relationship
between “art” and “science”? When you click on your applet to get a new image,
how much of that image is “your” creation – “your” art work? If you did not
create it, then who did? Take a walk under the falling leaves and discuss these
issues with your classmates.