Results 1 to 12 of 12
  1. #1
    Centinela66 is offline Member
    Join Date
    Sep 2008
    Posts
    5
    Rep Power
    0

    Angry First Applet not running on browsers

    I am writing my first applet. I have read some tutorials but I cant get it to run in my browser (it runs in the applet viewer though). Please be detailed in your answer because this is my first applet.
    This is the process I am following and the code:
    Using eclipse I created a project. Then right click on it to create a class (as in java applicatons). But i replaced the code in the class file for:

    package pkgs;
    import java.awt.*;
    import java.applet.*;
    public class FirstApplet extends Applet{
    public void paint(Graphics g){
    g.drawString("Simple applet", 20, 20);
    }
    }

    Then I run it as an applet and it worked in the applet viewer.

    Then I created a jsp page calling the applet:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>V2</title>
    </head>
    <body>
    <applet code="FirstApplet" width = "260"height = "200"></applet>
    </body>
    </html>

    Then I run it again and "Export" it to .WAR in my tomcat root directory. I am calling the page but it says:

    load: class FirstApplet not found.
    java.lang.ClassNotFoundException: FirstApplet

    The file FirstApplet.class is in the WEB-INF folder, under classes and the package name folder.

    I even tried to copy paste the .class file to the same directory as the .jsp file but no luck.

    What am I missing.

    Thanks in advance for your help.

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    6

    Default

    Hehe,to run Applet and integrate it into html you shouldn't export it as a WAR,export it as *jar,and create a simple html file.WAR file is the web dynamic project which contains Servlets and JSP files.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,576
    Rep Power
    23

    Default

    With this URL:
    http://127.0.0.1:8080/Norms/AppletReaderS.html
    I can load an HTML file and its jar file from
    "D:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\Norms\AppletReader.html"
    "D:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\Norms\AppletReader.jar"

    They are both in the same folder.
    The Applet tag:
    <APPLET CODE=AppletReader Archive=AppletReader.jar WIDTH=300 HEIGHT=300>
    <PARAM NAME=FILENAME Value="C:\\AppletTestFile.txt">
    </APPLET>
    Last edited by Norm; 09-21-2008 at 02:56 AM.

  4. #4
    jason wang is offline Member
    Join Date
    Sep 2008
    Posts
    16
    Rep Power
    0

    Default

    do you have put the class and the html code in a same directory. They must be in a same directory.

  5. #5
    Centinela66 is offline Member
    Join Date
    Sep 2008
    Posts
    5
    Rep Power
    0

    Default Still not working! any suggestions?

    The jar file is a compressed file, also the applet runs in the viewer but now in the browser. I also tried the other suggestion of copy pasting the class file to the same directory without luck.
    If the jar file needs to be generated as well as the war files for web projects that include applets could you please provide the steps to follow in eclipse to generate the compress file which could be used online?
    All I can see is the generation of a compress file (jar).
    I also tried to add codebase keyword in the <applet> tag, no luck either.
    Any other suggestions?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,576
    Rep Power
    23

    Default

    I gave you working HTML and paths to the files. Did you try that configuration?

  7. #7
    Centinela66 is offline Member
    Join Date
    Sep 2008
    Posts
    5
    Rep Power
    0

    Default no luck

    I tried that and didnt work.. the applet file was saved as a jar executable.. I used the export function of eclipse and selected jar file.
    i put a copy in the package/class/ folder and in the same folder as the jsp file and inserted the applet tags but no luck..
    Any ideas?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,576
    Rep Power
    23

    Default

    I tried that and didnt work.
    Did you try it exactly as I showed or did you change parts of it?
    Were the html page and the jar file in the same folder?
    The jsp page you posted looks exactly like an HTML page.
    What is the URL you enter in the browser to load the HTML page containing the applet?

  9. #9
    Centinela66 is offline Member
    Join Date
    Sep 2008
    Posts
    5
    Rep Power
    0

    Default please guide me through

    I have tried what you said but no luck... I might be exporting the jar file in a wrong way.
    Would you please tell me the steps to do that in eclipse? or JDeveloper...
    I included the code in the first post...
    thanks

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,576
    Rep Power
    23

    Default

    What do you see in the browser's java console window?
    I don't use those IDEs and can't help you with them.

  11. #11
    Centinela66 is offline Member
    Join Date
    Sep 2008
    Posts
    5
    Rep Power
    0

    Default error message

    Loading Java applet failed. in the status bar.
    then a popup appears which says:
    General Exception
    Name: FirstApplet
    java,lang.ClassNotFoundException: FirstApplet
    The box for the applet appears in the browser but with a default java icon.
    I have placed the .class file everywhere in the directory without luck.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,576
    Rep Power
    23

    Default

    What is in the java console? PLease copy and paste all of it without any edits.
    What browser are you using?
    Can you post your HTML?
    Can you load and execute the HTML with applet from a disk file without using a server?
    Get the HTML and applet to work from a disk file first, then move to doing it with a server.

Similar Threads

  1. Getting url of page applet is running on
    By damounh in forum Java Applets
    Replies: 1
    Last Post: 05-09-2008, 05:49 PM
  2. jsp running problem
    By bharanikumariyerjava in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-29-2008, 10:48 AM
  3. Sounds don't play when running applet
    By leonard in forum Java Applets
    Replies: 1
    Last Post: 08-06-2007, 08:08 PM
  4. Running a system
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 06-29-2007, 03:16 PM
  5. Replies: 4
    Last Post: 06-08-2007, 06:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •