hello .....i need to insert an image using swings in my project...but there is an error.....
the code is as shown below :-
import javax.swing.*;
import java.awt.*;
import java.io.*;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
class ImageFrame extends JFrame
{
ImageFrame(
String s)
{
setSize(800,600);
setTitle("imgtest");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
ImagePanel panel=new ImagePanel();
add(panel,BorderLayout.CENTER);
}
}
class ImagePanel extends JPanel
{
Image image;
ImagePanel()
{
try
{
image=ImageIO.read(new File("SunSet.jpg"));
}
catch(IOException e)
{
e.printStackTrace();
}
public void paintComponent(Graphics g)
{
g.drawImage(image,0,0,null);
}
}
}
public class image
{
/** Creates a new instance of image */
public image()
{
}
public static void main(String[] args)
{
ImageFrame frame=new ImageFrame("Image");
}
}