import java.awt.*; import java.net.*; import java.awt.event.*; /** *Draws a given image within a frame on the screen. * *Preconditions: *Postconditions: * *Sources:van der Linden, Just JAVA, 565-568 *Sources:Dale, Rebelsky, and Weems, Java Plus Data *Structures; Experiements in JAVA G2 * *@Author Gail Bonath *@author Joseph A. Pipkins *@author Minna Mahlab *@author Kate Ducey *@version 1.0 of October 26, 1999 * */ public class Display extends WindowAdapter implements ActionListener { // +--------+-------------------------- // | Fields | // +--------+ /** Frame used*/ protected Frame f; /** Area for output*/ protected Label out; /** Quit button*/ protected Button quit; // +--------------+--------------------- // | Constructors | // +--------------+ /** *Gets the specified image and sets up the Frame *where the image will be drawn. * */ protected Display(String username) { Image i = Toolkit.getDefaultToolkit().getImage("/home/bonath/csc152/project/" + username + ".jpg"); //Create the frame Frame f = new Frame("Gates Tower"); f.setSize(275,250); f.setLayout(new FlowLayout()); f.addWindowListener(this); //Create the canvas where the image will be shown MyCanvas mc = new MyCanvas(i); //Create the quit button. quit = new Button("Close"); quit.addActionListener(this); //Add the output areas to the interfaces. f.add(mc); f.add(quit); f.pack(); f.show(); } //Display() // +----------------+---------------------- // | Event Handlers | // +----------------+ public void actionPerformed(ActionEvent evt) { //Get the command String command = evt.getActionCommand(); //Should we quit? if (command.equals(quit.getLabel())) { f.dispose(); System.exit(0); }//if } // actionPerformed(ActionEvent) /** React to the closing of the window*/ public void windowClosing(WindowEvent e) { f.dispose(); System.exit(0); } // windowClosing() }//class Display