import java.awt.Graphics;
import java.awt.Panel;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
public class ShowImage extends Panel {
private static final long serialVersionUID = 1L;
private BufferedImage image;
public ShowImage(String filename) {
try {
image = ImageIO.read(new File(filename));
} catch (IOException ie) {
ie.printStackTrace();
}
}
public void paint(Graphics g) {
g.drawImage(image, 0, 0, null);
}
static public void main(String args[]) throws Exception {
JFrame frame = new JFrame("ShowImage.java");
Panel panel = new ShowImage(args[0]);
frame.getContentPane().add(panel);
frame.setSize(400, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
|