CSC 121A Lab 3 - Spring 2005

Thursday, January 20, 2005
Due: Wednesday, January 26, 2005, 5:00PM

[Course home page] [Java API Documentation]

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.)

Using Objects with Graphics

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]

Exercises (complete for homework)

 

Based on material from Deitel & Deitel, Java How to Program, 6e.



Last modified: Wed Jan 19 23:12:23 EST 2005