/*** FILENAME: GifReader.java CLASS: GifReader PURPOSE: This applet class will allow the user to enter the name of a GIF type image file and it will display it in a frame window. It makes use of the class ImageFrame which has methods in it to decompose an image into a pixel array (one dimensional or two-dimensional). Please see ImageFrame.java for more information. AUTHOR: Hanaa Barakat. Email: barakat@cs.queensu.ca ***/ /*** NOTE: if you try to load a file that the GifReader can't find or read, you may see the following error message appear in the terminal/system window Error loading image: sun.awt.motif.X11Image@7352bc Also, as far as I know, PNM type images aren't supported yet. If you need to convert a PNM file to GIF, use xv software in Unix, and save your image as type GIF. BUG NOTE: there seems to be a small bug with the program or with Java, I'm not sure, that makes the Frame that displays the image not resize properly to fit the image size. So it resizes to a smaller size than it should be. This is easily fixed manually by just dragging the edges of the frame out until the whole image is displayed. Documentation Note: I have documented the files assuming that you (the reader) have used Java before and can therefore understand how applets, frames and canvases are used. ***/ import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.net.URL; import java.lang.String; import java.awt.image.*; import java.util.*; /* this program will not open pnm files */ public class GifReader extends Applet implements ActionListener { private TextField filefield; private ImageCanvas imgCanvas; private ImageFrame imgFrame; private Image img; private static final String GO = "get file and measure features"; public void init() { Label prompt1; Button go; Panel firstPnl; /** set up user interface **/ firstPnl = new Panel(); firstPnl.setLayout(new BorderLayout()); Panel topPnl = new Panel(); prompt1 = new Label("Enter the training data file name:"); filefield = new TextField(15); go = new Button("DISPLAY IMAGE"); go.setActionCommand(GO); go.addActionListener(this); topPnl.add(prompt1); topPnl.add(filefield); firstPnl.add("North",topPnl); firstPnl.add("South",go); /** end of user interface setup **/ add(firstPnl); } // end of method init public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command == GO) { // user wants to view the image file String filename = filefield.getText(); img = getImage(getCodeBase(), filename); imgFrame = new ImageFrame(img); imgFrame.setSize(50,50); } } // end of method actionPerformed }