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.     private int width, height;
  7.     private OFImage panelImage;
  8.  
  9.     public ImagePanel() {
  10.         width = 360;
  11.         height = 240;
  12.         panelImage = null;
  13.     }
  14.  
  15.     public void setImage(OFImage image) {
  16.         if (image != null) {
  17.             width = image.getWidth();
  18.             height = image.getHeight();
  19.             panelImage = image;
  20.             repaint();
  21.         }
  22.     }
  23.  
  24.     public void clearImage() {
  25.         Graphics imageGraphics = panelImage.getGraphics();
  26.         imageGraphics.setColor(Color.LIGHT_GRAY);
  27.         imageGraphics.fillRect(0, 0, width, height);
  28.         repaint();
  29.     }
  30.  
  31.     public Dimension getPreferredSize() {
  32.         return new Dimension(width, height);
  33.     }
  34.  
  35.     public void paintComponent(Graphics g) {
  36.         Dimension size = getSize();
  37.         g.clearRect(0, 0, size.width, size.height);
  38.         if (panelImage != null) {
  39.             g.drawImage(panelImage, 0, 0, null);
  40.         }
  41.     }
  42. }
');