java - JApplet error that I can't seem to fix -


i getting annoying error java applet. new applets please note not experienced @ all.

i have html file labelled index.html following code:

    <html>        <head>             <title>applet jar example         </title>     </head>       <body>          <center>             <b>are ready dance??             </b>             <br>                 <br>                  <applet code="shawn/main.class" archive="lol.jar"                         width=400                       height=300>     </applet>    </center> </body>   </html> 

in same directory, have jar file labelled lol.jar following code:

package shawn;  import java.applet.audioclip; import java.awt.*; import java.io.file; import java.io.serializable; import javax.swing.*;  public class main extends japplet implements serializable {          image img = toolkit.getdefaulttoolkit().getimage("hey.gif");          @override         public void init(){             playsound();         }         @override     public void paint(graphics g)    {         g.drawimage(img, 0, 0, this);     }      public void playsound(){         audioclip ac = getaudioclip(getcodebase(), "hey.wav");         ac.play();     } } 

inside same directory, have 2 files labelled hey.wav, , hey.gif.

when execute page applet fails load, outputting message error. click details. when click, says:

runtimeexception

followed by...

java.lang.reflect.invocationtargetexception

everything works when run in eclipse, when export it. i`ll add more details if needed.

one definite problem in applet is:

image img = toolkit.getdefaulttoolkit().getimage("hey.gif"); 

if @ javadocs getimage(string) states:

returns image gets pixel data specified file, format can either gif, jpeg or png. underlying toolkit attempts resolve multiple requests same filename same returned image.

the highlight of file choice. applets , files used together, , not appropriate situation. instead image must accessed url.

applet offers instead applet.getimage(url) & getimage(url,string). 2nd particularly handy when need form url relative code base or document base.

if image located in same directory html, might loaded using along lines of:

image img = getimage(getdocumentbase(), "hey.gif"); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -