Chris Pollett >
Old Classes >
PIC20B

   ( Print View )

Enrollment info

Course Info: Homework Assignments: Practice Exams: PIC:
                            












HW#2 --- last modified January 16 2019 00:35:19..

Solution set.

Due date: April 24 8pm
=========

Files to be submitted: p20bhw2file1.java -- your graphics program
====================== p20bhw2file2.zip -- your images

HW2 Purpose:  To make a simple graphics program that allows the user
============  to take a collection of images and draw them to a JPanel
              at the user seclected location. The user can also load and
              save images. To gain experience with Streams, Vectors, and
              Random class.

Specification:
==============
For this homework you will write an application which open a window
that looks roughly like:

Draw Area:
__________________
|                |  [Icon Button 1]
|                |  [Icon Button 2]
|                |         :
|                |         :
|----------------|  [Icon Button n]

[Clear] [Open] [Save] [Random]

Note: n in the above must be at least 2.

When the user presses on an Icon Button and clicks on the Draw area, the image
on the icon is drawn at that location in the draw area. The clear button
clears the draw area. The open button and save buttons launch
JFileChoosers to allow the user to repsectively load a previous stored image
or save an image that was just created. The random button picks one
of the images on the Icon buttons at random (use the Random class)
and chooses a random location in the Draw Area and draws this image
to that location.

When the application is first launched the Icon buttons' images should be
loaded in from the file p20bhw2file2.zip. It should be the case if one
adds images to this zip file then additional Icon Buttons appear
without any change to the program. To load in the Icons, use
ObjectInputstream together with the ZipInputStream class.
Click here to see some example code of reading
and writing an icon. Note this example does not have any compression
but you should be able to add that without too much trouble using what we
learned in class.

Every time an image is placed on the Draw Area, an instance of the
class PictureElt which you create should be added to the Vector picture.
The class PictureElt should have an Icon attribute containing the Icon
and x, y attributes containing its coordinates. You should make this class
implement Serializable (just add this to the class definition you don't
actually have to write any methods). This just makes it so object of this
class can be written out to disk.  Also PictureElt should be a separate
class in the file not an inner class of the class p20bhw2file1 or
you will have trouble writing out your picture Vector.
The paintComponent method
of  the Draw Area JPanel should use an Vector picture when
it draws itself. When you do Open or Save the Vector picture
is the object that is read or written using an
ObjectInputStream/ObjectOutputStream.


Point Breakdown for HW2
=======================
Comments................................1pt
Icon buttons loaded in correctly
  from ZIP file.........................1pt
Icon Buttons works as described.........1pt
PictureElt class as described...........1pt
Open uses a JFileChooser................1pt
Open reads into object picture..........1pt
Save uses a JFileChooser................1pt
Save write out object picture...........1pt
Clear works and also clears picture.....1pt
Random works............................1pt

Total..................................10pts