package cs437.som.demo;

import javax.swing.*;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;

/**
* A simple frame for displaying a square scaledImage, scaled to 400x400 in a window.
*/
public class ImageFrame extends JPanel {
    private static final long serialVersionUID = 0L;
    
    /** The height and width dimension to which the scaledImage will be scaled */
    private static final int IMAGE_DIMENSION = 400;

    /** Image cache */
    private Image scaledImage;

    /**
     * Display an image in a new frame.
     *
     * @param image The image to display.
     */
    public ImageFrame(BufferedImage image) {
        setSize(IMAGE_DIMENSION, IMAGE_DIMENSION);
        this.scaledImage = image.getScaledInstance(IMAGE_DIMENSION, IMAGE_DIMENSION,
                Image.SCALE_DEFAULT);
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        g.drawImage(scaledImage, 0, 0, IMAGE_DIMENSION, IMAGE_DIMENSION, this);
    }

    @Override
    public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
        return (infoflags & ALLBITS) != 0;
    }

    @Override public String toString() { return "ImageFrame"; }

    /**
     * Create an ImageFrame and place it in a JFrame.
     *
     * @param title The title of the JFrame.
     * @param image The image to display.
     * @return A JFrame containing an ImageFrame.
     */
    public static JFrame createInJFrame(String title, BufferedImage image) {
        JFrame frame = new JFrame(title);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.getContentPane().add(new ImageFrame(image));
        frame.pack();
        return frame;
    }
}

@@ -505,17 +505,108 @@
 ledImage
-;
+ = null;%0A%0A    public ImageFrame() %7B%0A        setSize(IMAGE_DIMENSION, IMAGE_DIMENSION);%0A    %7D
 %0A%0A    /*
@@ -812,13 +812,187 @@
     
-this.
+setImage(image);%0A    %7D%0A%0A    /**%0A     * Set the image to display.%0A     * %0A     * @param image The image to display.%0A     */%0A    public void setImage(BufferedImage image) %7B%0A        
 scal
@@ -1178,16 +1178,55 @@
 int(g);%0A
+        if (scaledImage != null) %7B%0A    
         
@@ -1297,16 +1297,26 @@
  this);%0A
+        %7D%0A
     %7D%0A%0A 

Change ImageFrame from JFrame to JPanel; add convenience sf.