
import java.awt.*;

public class ImageViewerBean extends Component
{  public void setFileName(String f)
   {  fileName = f;
      image = Toolkit.getDefaultToolkit().getImage(fileName);
      setSize(getPreferredSize());
      repaint();
   }   

   public String getFileName()
   {  return fileName;
   }

   public void paint(Graphics g)
   {  if (image == null)   
      {  Dimension d = getSize();
         g.drawRect(0, 0, d.width, d.height);
      }
      else
         g.drawImage(image, 0, 0, this);
   }

   public Dimension getPreferredSize()
   {  if (image == null)
         return new Dimension(MINSIZE, MINSIZE);  
      return new Dimension(image.getWidth(null), 
         image.getHeight(null));
   }

   private static final int MINSIZE = 50;
   private Image image = null;
   private String fileName = "";
}




/*
 * Cay S. Horstmann & Gary Cornell, Core Java
 * Published By Sun Microsystems Press/Prentice-Hall
 * Copyright (C) 1997 Sun Microsystems Inc.
 * All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this 
 * software and its documentation for NON-COMMERCIAL purposes
 * and without fee is hereby granted provided that this 
 * copyright notice appears in all copies. 
 * 
 * THE AUTHORS AND PUBLISHER MAKE NO REPRESENTATIONS OR 
 * WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER 
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHORS
 * AND PUBLISHER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED 
 * BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING 
 * THIS SOFTWARE OR ITS DERIVATIVES.
 */
 
/**
 * @version 1.10 10 Mar 1997 
 * @author Cay Horstmann
 */




