Results 1 to 13 of 13

Thread: Applet help

  1. #1
    Billywizz is offline Member
    Join Date
    Jan 2011
    Posts
    57
    Rep Power
    0

    Default Applet help

    Hi i am quite advanced in java applications but i now want to learn how to make applets. I am following a very simple hello world tutorial online which is fine on the programming side but i cant seem to get the applet to actually show on the screen here is what have.

    Java Code:
    import java.applet.Applet;
    import java.awt.*;
    
    /**
     *
     * @author BillyWizz
     */
    public class GameApplet extends Applet {
    
        /**
         * Initialization method that will be called after the applet is loaded
         * into the browser.
         */
        public void init() {
            setSize(200,200);
            setBackground(Color.BLACK);
        }
        
        public void paint(Graphics g) {
            g.drawString("Hello", 30, 50);
            setBackground(Color.WHITE);
        }
        // TODO overwrite start(), stop() and destroy() methods
    }
    my applet created in netbeans
    I then have an index.html file including the app such that:

    Java Code:
    <HTML>
    <HEAD>
    <TITLE>Hello World Applet</TITLE>
    </HEAD>
    <BODY>
    <CENTER>
    <H1>Hello World Applet</H1>
    <APPLET CODE="GameApplet.class" WIDTH=150 HEIGHT=25></APPLET>
    </BODY>
    </HTML>
    when i open theindex.html file it loads the text in H1 and loads a box for the applet but inside the box it shows "Error click for details" When i click i get a box appear Headed Application error GameApplet.class There was an error while executing the application.

    Im sure theres something very simple im doing wrong as this is probably the most basic app "Hello world ". What am i doing wrong or what have i missed ?

    P.S i have JDK 1.7 with environmental settings path set to C:\Program Files\Java\jdk1.7.0\bin;
    and a new variable i created CLASSPATH set to .;C:\Program Files\Java\jdk1.7.0\lib

    Thanks hope this is enough information to help. Thanks.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Applet help

    A few things to try:

    Use JApplet not the Applet class.
    Remove the setSize() call since the applets size is being set by the web page
    Remove <CENTER> which is ill formed HTML
    Remove (unset) the CLASSPATH environment variable - or, at any rate, don't have it pointing to the lib directory

    and try

    Java Code:
    <APPLET CODE="GameApplet" WIDTH=150 HEIGHT=100></APPLET>
    (with GameApplet.class in the same directory as the HTML file.)
    Last edited by pbrockway2; 12-21-2011 at 11:00 PM.

  3. #3
    Billywizz is offline Member
    Join Date
    Jan 2011
    Posts
    57
    Rep Power
    0

    Default Re: Applet help

    Thanks for your reply still not working its saying on the error page .
    - Detected from bootclasspath: C:\\PROGRA~1\\Java\\jre7\\lib\\deploy.jar

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Applet help

    That's a trace message and not indicative of a problem. (See Bug ID: 7075195 Detected from bootclasspath: C:\\PROGRA~1\\Java\\jre7\\lib\\deploy.jar)

    Your code works fine for me with changes as noted above. In fact the applet runs whether specified by the class name or the class file name - but I'm using JRE 1.6_nn.
    Last edited by pbrockway2; 12-21-2011 at 11:31 PM.

  5. #5
    Billywizz is offline Member
    Join Date
    Jan 2011
    Posts
    57
    Rep Power
    0

    Default Re: Applet help

    Ok Thanks,
    Does it work on yours with Applet instead of JApplet?
    Or even my original ? just so i can see where the problem lies?

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Applet help

    Yes, exactly your code runs the applet without error. Nothing displays, but that's to be expected given how you set the size. But there are no errors.

  7. #7
    Billywizz is offline Member
    Join Date
    Jan 2011
    Posts
    57
    Rep Power
    0

    Default Re: Applet help

    Ok so must be my set up are you using netbeans? and explorer?
    my index.html is inside the project src folder alongside the GameApplet.java file
    I have jdk 1.7 is there any other packages i need? possibly sdk? iv herd this mentioned a few times when googling the problem? Or do i need to set up my environment system settings differently ?
    Realy want to get this sorted so i can start programming.

  8. #8
    Billywizz is offline Member
    Join Date
    Jan 2011
    Posts
    57
    Rep Power
    0

    Default Re: Applet help

    This is the message i get when i click the error message it takes me to the java console:

    Java Plug-in 10.1.0.8
    Using JRE version 1.7.0_01-b08 Java HotSpot(TM) Client VM
    User home directory = C:\Users\BillyWizz
    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------
    Detected from bootclasspath: C:\\PROGRA~1\\Java\\jre7\\lib\\deploy.jar

  9. #9
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Applet help

    I was using Eclipse. But I also took the compiled code (GameApplet.class) and put it on my desktop along with an HTML file containing what you had. I opened the HTML file in Chrome and Firefox.

    "sdk" is just a generic term that people use sometimes for the jdk, so I wouldn't worry about that. You have it, or Netbeans would be compiling the code.

    If you are seeing the web page at all (eg the heading), then you have the file in the right place as far as Netbeans is concerned. If in doubt do what I did and copy both the .class and .html files to somewhere else and open the page from there. I don't have a copy of Netbeans handy, but there should be some sort of of option to "Run as applet" - perhaps someone can confirm that. If the applet runs OK in appletviewer that would point the finger of suspicion in the direction of your browser.

    The Java console output you posted is not actually showing any sort of error. One thing you could do is add a System.out.println("Some message"); to the applet's init() and see if the message gets printed to the Java console. Also you could try opening the web page in different browsers in case there is some problem with InternetExplorer's java plugin.
    Last edited by pbrockway2; 12-22-2011 at 12:52 AM.

  10. #10
    Billywizz is offline Member
    Join Date
    Jan 2011
    Posts
    57
    Rep Power
    0

    Default Re: Applet help

    Thanks for your help i will try that

  11. #11
    Billywizz is offline Member
    Join Date
    Jan 2011
    Posts
    57
    Rep Power
    0

    Default Re: Applet help

    Ok i just ran the applet in netbeans using run file and it worked using the applet viewer i will try using a different browser

  12. #12
    Billywizz is offline Member
    Join Date
    Jan 2011
    Posts
    57
    Rep Power
    0

    Default Re: Applet help

    Ok just tried it in chrome and it still saying the same thing this suggests to me that it is the html file that isnt working?

  13. #13
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Applet help

    You might want to try on another computer (with a different java runtime installation). I'm using WindowsXP and 1.6 and I don't see the problem. (Sorry)

Similar Threads

  1. Replies: 30
    Last Post: 08-26-2011, 10:05 PM
  2. applet working in applet viewer, not browser
    By plasticfood in forum Java Applets
    Replies: 4
    Last Post: 06-24-2011, 07:47 PM
  3. Replies: 2
    Last Post: 09-29-2009, 04:33 PM
  4. Calling another applet on click of button in one applet
    By niteshwar.bhardwaj in forum Java 2D
    Replies: 1
    Last Post: 02-19-2009, 01:54 PM
  5. Replies: 4
    Last Post: 06-08-2007, 07: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
  •