document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.awt.image.*;
  4.  
  5. public class ImagePanel extends JComponent
  6. {
  7.     private int width;
  8.     private int height;
  9.     private OFImage panelImage;
  10.  
  11.     /**
  12.      * Constructor for objects of class ImagePanel
  13.      */
  14.     public ImagePanel()
  15.     {
  16.         width = 160;
  17.         height = 240;
  18.         panelImage = null;
  19.     }
  20.    
  21.     public void setImage(OFImage image)
  22.     {
  23.         if(image != null)
  24.         {
  25.             width = image.getWidth();
  26.             height = image.getHeight();
  27.             panelImage = image;
  28.             repaint();
  29.         }
  30.     }
  31.  
  32.     /**
  33.      * An example of a method - replace this comment with your own
  34.      *
  35.      * @param  y  a sample parameter for a method
  36.      * @return    the sum of x and y
  37.      */
  38.     public void clearImage()
  39.     {
  40.         Graphics imageGraphics = panelImage.getGraphics();
  41.         imageGraphics.setColor(Color.LIGHT_GRAY);
  42.         imageGraphics.fillRect(0, 0, width, height);
  43.         repaint();
  44.     }
  45.    
  46.     public Dimension getPreferedSize()
  47.     {
  48.         return new Dimension(width, height);
  49.     }
  50.    
  51.     public void paintComponent(Graphics g)
  52.     {
  53.         Dimension size = getSize();
  54.         g.clearRect(0, 0, size.width, size.height);
  55.         if(panelImage != null)
  56.         {
  57.             g.drawImage(panelImage, 0, 0, null);
  58.         }
  59.     }
  60. }
');