
Hi,
This is my code. In this I am unable to load the image.I want to know the problem with this code.
import java.awt.*;
import java.awt.event.*;
public class AwtImg extends Frame
{
Image img;
public static void main(String args[])
{
AwtImg ai=new AwtImg();
}
AwtImg()
{
super("Image Frame");
MediaTracker mt=new MediaTracker(this);
img=Toolkit.getDefaultToolkit().getImage("swamiji.jpeg");
mt.addImage(img,0);
setSize(400,400);
setVisible(true);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
dispose();
}
});
}
public void update(Graphics g){
paint(g);
}
public void paint(Graphics g){
if(img != null)
g.drawImage(img, 100, 100, this);
else
g.clearRect(0, 0, getSize().width, getSize().height);
}
}
Thank You
srihari
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.