Demo Image Loader


import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.*;

class ImagePanel extends JPanel{

private BufferedImage image;

public ImagePanel() {
try {
image = ImageIO.read(new File("photo.jpeg"));
} catch (IOException ex) {
// handle exception...
}

}

@Override
public void paintComponent(Graphics g) {
g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters

}

}

public class DemoImageLoader
{
JFrame mf;
ImagePanel ip;
JPanel jp;
DemoImageLoader()
{
mf=new JFrame("Image Loader");
ip=new ImagePanel();
jp=new JPanel();
jp.add(ip);
mf.add(ip);

mf.setSize(200,300);
mf.setVisible(true);
}
public static void main(String []a)
{
new DemoImageLoader();
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s