diff options
Diffstat (limited to 'src/jake2/imageio/ImageFrame.java')
-rw-r--r-- | src/jake2/imageio/ImageFrame.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/jake2/imageio/ImageFrame.java b/src/jake2/imageio/ImageFrame.java new file mode 100644 index 0000000..52cf9e4 --- /dev/null +++ b/src/jake2/imageio/ImageFrame.java @@ -0,0 +1,63 @@ +/* + * Created on Apr 26, 2003 + * + */ +package jake2.imageio; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.image.BufferedImage; +import javax.swing.JFrame; + +/** + * @author cwei + * + */ +public class ImageFrame extends JFrame { + + BufferedImage image; + Component pane; + + public ImageFrame(BufferedImage image) { + super(); + this.image = image; + + pane = getContentPane(); + setIconImage(image); + setSize(640, 480); + + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + } + + public void paint(Graphics g) { + super.paint(g); + Graphics2D g2 = (Graphics2D) pane.getGraphics(); + if (this.image != null) { + g2.drawImage( + image, + Math.max(0, (getWidth() - image.getWidth()) / 2), + Math.max(0, (getHeight() - image.getHeight()) / 2), + Color.LIGHT_GRAY, + pane); + } else { + g2.drawString( + "EMPTY IMAGE", + this.getWidth() / 4, + this.getHeight() / 2); + } + } + + public void showImage(BufferedImage image) { + this.image = image; + this.repaint(); + } + +} |