Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

want to draw an image on to Frame  RSS feed

 
sathish gopal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi folks
I would like to draw an image(GIF or JPEG) on to Frame Windows.I didnot find any method in the java API.
But I did find a method to drawImage in applet.
Know my Idea is draw the required image on the Applet and then add the Applet to the Frame Window.
I thought this will work but to my annoyance it didnot
Help in this regard
Following is the code
import java.awt.*;
import java.applet.*;
//<applet code=demo width=500 height=500></applet>
public class demo extends Applet{
public Image im;
public void init(){
try{
im=getImage(getCodeBase(),"some.gif");

}catch(Exception e){System.out.println(e);}

}
public void start()
{
repaint();
}
public void paint(Graphics g)
{
try{

g.drawImage(im,25,25,this);
}
catch(Exception e){System.out.println(e);}
}
public static void main(String args[])
{
Frame f=new Frame();
Applet app =new demo();
app.init();
app.start();
f.add(app);
f.setSize(500,500);
f.setVisible(true);
}
}
Thank u in advance

 
sathish gopal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks
I didnot mention the kind of run time error it is throwing..
The error is
java.lang.NullPointerException
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At what line? You may be trying to paint an image that didn't load. This looks like the most likely problem to me. Try using a MediaTracker to verify that your image has loaded before you try to use it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!