import java.awt.Frame;
import java.awt.event.*;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.MediaTracker;
import java.net.URL;
/**
 * Creates a frame with an image that closes
 *
 * @version 1.1 of 3 November 1999
 * @author Gail Bonath
 * @author Joe Pipkins
 * @author Minna Mahlab
 * @author Kate Ducey
 */

class FrameWithImage extends Frame {

    /************
     |  Fields  |
     ************/ 
    protected URL filename;
    protected String username;
    protected Image image;
    // String defaultimage;

    /***************
     * |Constructor|
     * *************
     * create a frame
     */

    public FrameWithImage (URL filename, String username) 
        throws Exception {
        try {
            image = Toolkit.getDefaultToolkit().getImage(filename);
        } // try
        catch (Exception e) {
            throw e;
        } // catch

        // Wait until the image has loaded.  Help from SamR.
        // (1) Set up a MediaTracker for this frame.  MediaTrackers know
        //     how to track media.  In particular, they know how to wait
        //     until images are done loading.
        MediaTracker helper = new MediaTracker(this);
        // (2) Tell the MediaTracker to track our image.
        helper.addImage(image, 0);
        // (3) Tell the MediaTracker to wait until that image is done loading.
        try {
          helper.waitForAll();
        }//try
        catch (InterruptedException e) {
            //  defaultimage = "/home/ducey/cs152/project/grin.jpg";
        
          // Do nothing for now.
        }//InterruptedException 
        // That's it.

        setTitle (username);
        setSize (200,250);
        addWindowListener (new WindowAdapter()
                           {public void windowClosing (WindowEvent e)
                               {System.exit (0);
                               }
                           });
    }//FrameWithImage()
    
    //paint the image
    public void paint (Graphics g){
        g.drawImage (image, 0, 0, this);

    }//paint
}//FrameWithImage
