Answer all bulleted questions. Upload your answers and program files to the VikingWeb coursework section. Besides uploading your written answers to the VikingWeb, please turn in a printed copy either in class on the due date or leave a copy in the box outside my door later on during the day. (You may turn in the printed copies later than 5PM on the due date, but the files must be uploaded to VikingWeb at or before 5PM.)
Most of the graphics programs we wrote in previous labs did
not change behavior each time the program was executed. The
exception was the last homework assignment which asked you to
write a program that displayed shapes at random. The problem
with that program was that each time the panel needed to be
redrawn on the screen, the drawing changed. To create a more
consistent drawing that remains the same each time it is
drawn, we have to store information about the shapes and
colors so that they can be reproduced in the same way each
time the paintComponent
method is called by the
Java system.
To do this, let's design a set of classes to store
information about the shapes we wish to draw. Objects of these
classes will be "smart" enough to draw themselves given a
Graphics
object. Download and examine the
following files and then run the TestDraw
application to see how this program works:
[MyLine.java]
[DrawPanel.java]
[TestDraw.java]
MyRectangle
, MyOval
, and
MyTriangle
. All of these classes should include
x1, y1, x2, y2 coordinates, a color and a boolean
flag to determine whether the shape is a filled
shape. Declare constructors for each class with arguments for
initializing all the fields (instance variables). Define
draw
methods for each class appropriately. To
draw triangles, use the
fillPolygon
method of the Graphics
class.
Add arrays to the class DrawPanel
for each
shape type. The length of each array should be a random
number between 1 and 5. The constructor of class
DrawPanel
should fill each of the arrays with
shapes of random positions, size, and fill.
The first step of the project is to form groups of three or four people each. You should have your group identified by next Wednesday (January 26). Please email me the list of your group members by that date.
Once you have identified your group, you should start looking over the project description (click here). There is not much on the page at this point but it will be updated over the next week.
Based on material from Deitel & Deitel, Java How to Program, 6e.