9 Replies Latest reply: Sep 17, 2011 8:36 AM by 793415 RSS

    Applet-problem

    REDO LOG
      hello everyone, iwish you all doing well, however, i need your help with applets

      i have a problem in an applet, the apllet code is(the java file is named : Appplet.java):
      package projet;
      import java.applet.Applet;
      import java.awt.Graphics;
      
      
      public class Appplet extends Applet {
      
          @Override
      
         public void paint(Graphics g)
          {
             for(int i=0; i<5;i++)
               {
                 g.drawString("helloWorld", 10, i*15);
               }
          }
      }
      i compile the java file to get the class file then i write the following html page (named: applet.html):



      <HTML>
      <BODY>
      <APPLET CODE = "Appplet.class"
      WEIDTH = 300 HEIGHT = 120 >
      </APLLET>
      </BODY>
      </HTML>




      but when i open it with a brpwser i got an error at the top-left of the page

      is there any thing wrong with the code? or i have to configure somthing before working with applets?

      thanks for any intervention.
      regards
      Rachid

      Edited by: EJP on 17/09/2011 09:23: Corrected misspelling in title. Added code tags. Moving to the Applets forum from the amazingly irrelevant forum you posted it in.
        • 1. Re: Applet-problem
          EJP
          There are several spelling errors in your HTML.

          When posting or reporting problems, here or anywhere, it is not sufficient to say you 'got an error'. You have to state what it was, and verbatim rather than by paraphrase.
          • 2. Re: Applet-problem
            REDO LOG
            here is the error:





            Java Plug-in 1.6.0_26
            Utilisation de la version JRE 1.6.0_26-b03 Java HotSpot(TM) Client VM
            Répertoire d'accueil de l'utilisateur = C:\Users\rachid
            ----------------------------------------------------
            c: effacer la fenêtre de la console
            f: finaliser les objets de la file d'attente de finalisation
            g: libérer la mémoire
            h: afficher ce message d'aide
            l: vider la liste des chargeurs de classes
            m: imprimer le relevé d'utilisation de la mémoire
            o: déclencher la consignation
            q: masquer la console
            r: recharger la configuration des politiques
            s: vider les propriétés système et déploiement
            t: vider la liste des threads
            v: vider la pile des threads
            x: effacer le cache de chargeurs de classes
            0-5: fixer le niveau de traçage à <n>
            ----------------------------------------------------


            java.lang.NoClassDefFoundError: Appplet (wrong name: projet/Appplet)
                 at java.lang.ClassLoader.defineClass1(Native Method)
                 at java.lang.ClassLoader.defineClassCond(Unknown Source)
                 at java.lang.ClassLoader.defineClass(Unknown Source)
                 at java.security.SecureClassLoader.defineClass(Unknown Source)
                 at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
                 at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
                 at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
                 at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
                 at java.lang.ClassLoader.loadClass(Unknown Source)
                 at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
                 at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
                 at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
                 at java.lang.Thread.run(Unknown Source)
            Exception : java.lang.NoClassDefFoundError: Appplet (wrong name: projet/Appplet)
            • 3. Re: Applet-problem
              793415
              <HTML>
              <BODY>
              <APPLET 
                CODE="Appplet.class"
                WEIDTH=300 
                HEIGHT=120 >
              </APLLET>
              </BODY>
              </HTML>
              Should be..
              <HTML>
              <BODY>
              <APPLET 
                CODE="projet.Appplet"
                WIDTH=300 
                HEIGHT=120 >
              </APPLET>
              </BODY>
              </HTML>
              The are three (3) differences between the two HTML fragments. It would pay to validate the rest of the HTML using a DTD. Especially if it is of the same general quality as the applet element.

              To work, the structure will need to be like this:

              <ul>
              <li>appletdirectory/
              <ul>
              <li>applet.html
              <li>projet/
              <ul>
              <li>Appplet.class</li>
              </ul>
              </ul>
              </ul>
              • 4. Re: Applet-problem
                REDO LOG
                i will make everything clear:


                i created an Appplet.txt file in the desktop and wrote the code in it, then i changed the extension to a java file (it becomes Appplet.java)
                after that i open the CMD and compile the Appplet.java file using javac command (because i need to generate the .class file i.e Appplet.class ); after, i create the associated html page named : page.html and wrote the code :


                <HTML>
                <BODY>
                <APPLET
                CODE="Appplet.class"
                WIDTH=300
                HEIGHT=120>
                </APPLET>
                </BODY>
                </HTML>



                in it;
                but when i open the html page i got the previous error
                • 5. Re: Applet-problem
                  793415
                  raccio wrote:
                  i will make everything clear:
                  What is the directory structure of the dirs containing the HTML and applet class?
                  but when i open the html page i got the previous error
                  Why did you ignore the advice about the package? If you want to make this simple, remove the package statement in the code and recompile it. If you want to get it working with the package statement - follow my instructions.
                  • 6. Re: Applet-problem
                    REDO LOG
                    i literally followed what you explaind, it works

                    but i still don't know why it does'nt work with my methode( putting the Appplet.class and page.html in the same folder )
                    • 7. Re: Applet-problem
                      793415
                      raccio wrote:
                      i literally followed what you explaind, it works
                      So my reply was correct? Maybe you should mark it as such. Feel free to mark other replies as 'helpful' as you see fit.
                      but i still don't know why it does'nt work with my methode( putting the Appplet.class and page.html in the same folder )
                      It all comes down to these lines in the applet code.
                      package projet;
                      ...
                       
                      public class Appplet ...
                      <ul>
                      <li>The fully qualified name of the class produced by that source is <tt>projet.Appplet</tt>.
                      <li>The <tt>code</tt> attribute of the <tt>applet</tt> element expects the FQN as a value.
                      <li>When the JRE sees that value it looks for the class at <tt>projet/Appplet.class</tt> relative to the code base of the applet.
                      <li>The applet element specifies no code base so it defaults to the directory in which the HTML is located.
                      <li>If the URL to the HTML is (1), the code base is (2), & the path that the JRE expects to find the class file is (3).
                      <ol>
                      <li>http://our.com/the/applet.html
                      <li>http://our.com/the/
                      <li>http://our.com/the/projet/Appplet.class
                      </ol>
                      </ul>

                      That is just the way it works. You can avoid putting the class file in a sub-directory by putting it in a Jar file in the same directory as the applet, and adding it to the <tt>archive</tt> attribute. But the class still needs to be in a path of the Jar that reflects the package information, or those same type of errors will result.
                      • 8. Re: Applet-problem
                        REDO LOG
                        i forgot to mark, sorry , thank you again
                        • 9. Re: Applet-problem
                          793415
                          You're welcome. Glad you got it sorted.