I am trying to publish the applet on the web. I know the syntax of the <applet>
tag, and the icons for the buttons I am using are in the same folder as all of the classes. I don't know what is wrong. Here is the code:
<applet code="Bomb.class" codebase="..//..//build//classes" width="650" height="450">
<p>This requires a java-enabled browser</p>
</applet>
Ple开发者_开发知识库ase help. :(
While publishing an applet, you really should create a jar
file with the Applet's classes and resources (such as images) in it. Then you can use Class
's getResource
to get a Url
for it, like this:
ImageIcon myImage = new ImageIcon(this.getClass().getResource("/img.jpg"));
The /
is necessary because of how Class
's getResource
works.
Try this
Image myImage= getImage(getDocumentBase(),"img.jpg");
ImageIcon imgIcon = new ImageIcon(myImage);
精彩评论