Posted By:
RAKHI_SAXENA
Posted On:
Wednesday, August 15, 2001 10:04 PM
1. Does getImage work on Netscape Navigator? When I load pictures to my applet, NN's java console doesn't say anything.After creating a new Panel that actually uses the Images, applet gives a nullPointerException because of the images. The same code works in Internet Explorer (and suprise, suprise with appletviewer). 2. What ways do I have for loading Images to my applet? Is there an optional way other than getImage? Thanks in advance, Rakhi Here's the code sample : The commented areas are the various possiblities I have tried without success. import java.awt.*; import java.net.*; import java.awt.image.*; import java.applet.*; public class ImageT
More>>
1. Does getImage work on Netscape Navigator? When I load pictures to my applet, NN's java console doesn't say anything.After creating a new Panel that actually uses the Images, applet
gives a nullPointerException because of the images. The same code works in Internet Explorer (and suprise, suprise with appletviewer).
2. What ways do I have for loading Images to my applet? Is there
an optional way other than getImage?
Thanks in advance,
Rakhi
Here's the code sample :
The commented areas are the various possiblities I have tried without success.
import java.awt.*;
import java.net.*;
import java.awt.image.*;
import java.applet.*;
public class ImageTrial extends Applet {
Image baseImage;
public void init() {
baseImage = getImage(getCodeBase(),"xxx.gif");
//baseImage = getImage(getDocumentBase(),"xxx.gif");
/*try {
URL u = new URL("http://localhost:8080/xxx.gif");
baseImage = getImage(u);
} catch (MalformedURLException m) {m.printStackTrace(); }
*/
/*try {
URL u = new URL("http://127.00.00.01/xxx.gif");
baseImage = getImage(u);
} catch (MalformedURLException m) {m.printStackTrace(); }
*/
/*try {
URL u = new URL(getDocumentBase(),"xxx.gif");
baseImage = getImage(u);
} catch (MalformedURLException m) {m.printStackTrace(); }
*/
/*MediaTracker mt = new MediaTracker(this);
mt.addImage(baseImage,0);
try {
mt.waitForID(0);
}
catch (InterruptedException e) { e.printStackTrace(); }
*/
if (baseImage == null)
System.out.println("image is null");
else
System.out.println("image is not null");
repaint();
}
public void paint(Graphics g) {
if (baseImage == null)
g.drawString("IMAGE DISPLAY ERROR:IMAGE IS NULL",10,10);
else
g.drawImage(baseImage,10,10,this);
}
}
The following is the HTML code:
//
//
<<Less