[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

Loading images in Java Applet

Hi,

I would like to download images in a java applet, for displaying at any given time - i.e. getting the image from the server into an Image variable which can then be added to a Canvas or something similar.
I've experimented with getImage and MediaTracker, as in the code below, but am getting NullPointerException returned when it comes to adding the Image to the canvas.
In the code below, iCanvas is a class which adds the image object to an array and then draws all stored ones.
Any ideas (or a better way to do this)?
Image spl=getImage(getDocumentBase(),"LoadScreen.jpg");
MediaTracker mt=new MediaTracker(this);
mt.addImage(spl,1);
try
{
    mt.waitForAll();
}
catch(Exception e)
{
}
iCanvas.addimagetodisplay(spl,0,0); //Null pointer exception at this line

Open in new window

0
samwaters
Asked:
samwaters
2 Solutions
 
sciuriwareCommented:
If you load images as ImageIcon monitoring is automatic:

     new ImageIcon(String pathname);

or

    new ImageIcon(URL path);

;JOOP!
0
 
objectsCommented:
> iCanvas.addimagetodisplay(spl,0,0); //Null pointer exception at this line

check iCanvas has been initialized
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now