Creating and running a Java applet -


i thought try hand @ applets - made applet using eclipse. runs fine using run -> java applet.

i read bit running outside eclipse, did following:

  1. made folder.
  2. created new -> java project [applet_test].
  3. inside project, created new -> other -> visual swing class -> applet [number1] - created number1.class.
  4. added code , ran java applet - ran fine.
  5. exported project jar file (not runnable jar file).
  6. wrote html using textedit (mac's version of windows' notepad). html follows, below...
  7. i put jar file, html , .class file in folder.
  8. in terminal (mac's version of windows command prompt window), ran appletviewer applet_testx2.html (that's name of html).
  9. i see brief flash of application name @ top of screen (as other running application).

however, application (which should display jpanel label , button) did not appear. tried running firefox , safari. html code appeared.

so, doing wrong? and, more importantly, how do correctly?

code follows without imports statements:

<html>     <body>         <applet code="number1.class" archive="applet_test.jar"             width=300             height=300>         </applet>     </body> </html> 

the java code:

public class number1 extends japplet {     public number1() {      }      private static final long serialversionuid = 1l;      @override     public void init() {         try {             eventqueue.invokeandwait(new runnable() {                 @override                 public void run() {                     initcomponents();                 }             });         }         catch (exception ex) {             ex.printstacktrace();         }     }     private void initcomponents() {         setsize(320, 240);          jpanel panel = new jpanel();         getcontentpane().add(panel, borderlayout.center);          jlabel lblapplettest = new jlabel("applet test 1");         panel.add(lblapplettest);          jbutton btnpushit = new jbutton("push it");         panel.add(btnpushit);     } } 

firefox source view:

<!doctype html public "-//w3c//dtd html 4.01//en" "http://www.w3.org/tr/html4/strict.dtd"> <html>     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8">         <meta http-equiv="content-style-type" content="text/css">         <title></title>         <meta name="author" content="bt">         <meta name="generator" content="cocoa html writer">         <meta name="cocoaversion" content="1038.35">         <style type="text/css">             p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px helvetica}             p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px helvetica; min-height: 19.0px}         </style>     </head>     <body>         <p class="p1">&lt;html&gt;</p>         <p class="p1"><span class="apple-converted-space"> </span>&lt;body&gt;</p>         <p class="p1"><span class="apple-converted-space">   </span>&lt;applet code="number1.class" archive="applet_test.jar"</p>         <p class="p2"><br></p>         <p class="p1"><span class="apple-converted-space">    </span>width=300</p>         <p class="p1"><span class="apple-converted-space">   </span>height=300&gt;</p>          <p class="p1">&lt;/applet&gt;</p>         <p class="p1">&lt;/body&gt;</p>         <p class="p1">&lt;/html&gt;</p>     </body> </html> 

my guess here:

<applet code="number1.class" archive="applet_test.jar" 

you're not taking packages consideration. instance, if package mypackage.vol3 line should read

<applet code="mypackage.vol3.number1.class" archive="applet_test.jar" 

but if doesn't help, you'll want extract error messages browser gives , edit original post show are.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -