 |
Assignment 5
|
Due: 27 April 2000, beginning of class. STAPLED!
Image Display Tool (100 points)
This program will allow you to display and manipulate images (i.e., jpg and
gif files). To understand what your program will do,
- Download the following files:
- IPlayer.class
- ImageGUI.java
- ImageLabel.java
- pics.txt
- Compile the Java source files.
- Execute the command
java IPlayer
- In the filename field, enter the file name pics.txt and then press the
process button. This will create two button widgets, one labeled
Duke and one labeled Yanks. (Note - you may need to resize your
GUI to see the buttons.)
- Press the Duke button. This will fill in the name in the current
image field. Alternatively, you can enter the name Duke in the current
image field.
- Press any the DISPLAY button. This will pop up a new GUI with
an image. To close the image, press the CLOSE button.
- Try the BW and FLIP buttons.
- Press the Yanks button now. Again, try the DISPLAY,
BW and FLIP buttons.
In this assignment, you will need to write a class called ImagePlayer, which
is a GUI that should work similarly to the IPlayer program that you
executed above. We have provided a skeleton in
ImagePlayer.java. Before explaining how you should
proceed, we first need to understand some of the files you downloaded:
- ImageLabel.java - The ImageLabel class
is a widget used to represent images, such as jpg and gif files. An
ImageLabel widget can be added to a GUI like any other widget. Examine
the source for this class. The methods that are relevant for this assignment are:
// Default constructor - creates a simple image
public ImageLabel ()
// Constructor that takes a URL and a name for an image.
// For example:
// ImageLabel i =
// new ImageLabel ("http://www.dinosaur-museum.org/dinosun.jpg", "Allosaurus");
public ImageLabel (String url, String name)
// Get the name associated with an ImageLabel
public String getName ()
// Get a Black and White version of an ImageLabel
public ImageLabel bw ()
// Get a flipped version of an ImageLabel
public ImageLabel flop ()
- ImageGUI.java - The ImageGUI class is
used to display an image. Again, examine the source. You can create an
ImageGUI object by invoking the ImageGUI constructor sending
an ImageLabel object as an argument. For example:
ImageLabel i =
new ImageLabel ("http://www.dinosaur-museum.org/dinosun.jpg", "Allosaurus");
new ImageGUI (i);
These two statements will cause a new GUI window to pop up with your image
displayed. You can close the window by clicking the CLOSE button. As
you can see, this invokes the hide() method, which closes the GUI.
- pics.txt - This file shows what the format for
the input file. Examine this file. Each entry consists of two lines: the
image name and the URL for the image. For example, the entry:
roos
http://www.onthenet.com.au/~jbergh/roo65.jpg
says that the name of the image is roos and its URL is http://www.onthenet.com.au/~jbergh/roo65.jpg.
What your GUI needs to do:
- Create a GUI with a layout similar to the GUI we have provided.
- When the PROCESS button is pressed, the file containing the image
names and URLS is read in to a Vector of ImageLabel objects.
Recall that an ImageLabel object is created using an image name
and URL.
- Using this Vector, create the Button widgets labeled with the image
names and add these widgets to your GUI.
- When the image name button is pressed, the image name associated with the
button pressed should be displayed
in the current image text field. Alternatively, a user may manually enter
the image name in the current image text field.
- When a user clicks either the DISPLAY, BW or FLIP
button, the appropriate image, i.e., the one with the current
image name, should be shown. If the image name is invalid, an error
message should be displayed in the message text field. What this means is
that you will need to search the Vector of ImageLabel objects
for the given image name.
- If the user enters a new file name and presses PROCESS again, the old
image name buttons should be removed from the GUI before displaying the new
image name buttons.
Some methods you might need:
- The Vector class defines the method
public void removeAllElements ()
which removes all the elements in a Vector.
- The GUI class provides the add method for adding
widgets to a window. The GUI class also provides:
public void remove (Object o)
for removing widgets from the window.
- Note that to set the color (background and foreground) of a widget, you can
use the setBackground and setForeground methods. For example:
Button b = new Button ("PRESS ME");
b.setBackground (Color.blue);
b.setForeground (Color.white);
You can use other colors as well -- use standard color names.
 |
 |
 |
 |
 |
 |