2 import java
.awt
.Graphics
;
4 import java
.awt
.image
.BufferedImage
;
5 import java
.io
.IOException
;
8 import javax
.imageio
.ImageIO
;
9 import javax
.swing
.JFrame
;
11 public class ShowImage
extends Panel
{
19 URL input
= this.getClass().getResource(("imgs/test.png"));
20 // this will read the image to save
21 // into a BufferedImage variable
22 image
= ImageIO
.read(input
);
23 } catch (IOException ie
) {
29 System
.out
.println("Error: " + ie
.getMessage());
33 public void paint(Graphics g
) {
34 // This is to actually draw the image out,
37 // Input of a bufferedimage, x, y, then
38 // an observer in this case null.
39 g
.drawImage(image
, 0, 0, null);
42 static public void main(String args
[]) throws Exception
{
43 // Creates a window to
45 JFrame frame
= new JFrame("Display image");
47 // Gets the image from ShowImage() method
48 Panel panel
= new ShowImage();
50 // Adds the image to the new window
52 frame
.getContentPane().add(panel
);
54 // sets the size of the panel
55 frame
.setSize(500, 500);
57 frame
.setVisible(true);