Results 1 to 18 of 18
  1. #1
    matejm1994 is offline Member
    Join Date
    Dec 2010
    Posts
    14
    Rep Power
    0

    Default How to add Applet in HTML site

    Hell all,

    I made one sample Applet game for school homework. (It's TicTacToe) But now, I have to make this application works in web browser. I try some ways, but no one didn't work. I made my Applet using Eclipse. Also, I search on google, but I haven't found any solution. TicTacToe.class is save in Desktop, and thsi HTML code is save in desktop too.

    I need to make this program to tomorrow, so if anyone know the solution...

    Java Code:
    <HTML>
     <HEAD>
    
     <TITLE>test</TITLE>
    
     <BODY>
     <CENTER>
     <APPLET CODE = 'TicTacToe.class' WIDTH = 300 HEIGHT = 300 </APPLET>
    </CENTER>
     </BODY>
     </HTML>

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default

    Erm, I'm pretty sure you need a Jar, not just a class file.

    Recommended reading: Lesson: Applets (The Java™ Tutorials > Deployment)
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,419
    Rep Power
    25

    Default

    It should work without a jar file.

    Are there any error messages in the browser's Java console? Copy and paste them here.

    Remove the .class from the code= attribute. It should be the name of the class, not the name of a file.

    Also fix your <APPLET tag. Its missing the ending >

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default

    Quote Originally Posted by Norm View Post
    It should work without a jar file.
    Ah! Very cool, I did not know that. You learn something every day!
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,419
    Rep Power
    25

    Default

    Yeah, these forums are great for that.

  6. #6
    matejm1994 is offline Member
    Join Date
    Dec 2010
    Posts
    14
    Rep Power
    0

    Default

    Hello again. Thanks to all for replies =)

    Norm: Now, when I fix the missing ending in <APPLET>, now there is no error anymore. But now the Applet just won't start. When I open a browser (Opera or IE), there is just a cup of coffee and there is a blue circle which revolves around a cup of coffee.
    But I have no idea what can be wrong.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,419
    Rep Power
    25

    Default

    See the second line of post #3

    What is in the Java Console?

  8. #8
    matejm1994 is offline Member
    Join Date
    Dec 2010
    Posts
    14
    Rep Power
    0

    Default

    Hi,

    so, if I open Java Console, there id this:
    Java Plug-in 1.6.0_24
    Using JRE version 1.6.0_24-b07 Java HotSpot(TM) Client VM
    User home directory = C:\Users\matejm1994
    ----------------------------------------------------
    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>
    ----------------------------------------------------


    APPLET tag missing CODE parameter.
    And I repair the HTML Code. Now it is like that:
    Java Code:
    <HTML>
     <HEAD>
    
     <TITLE>test</TITLE>
    
     <BODY>
     <CENTER>
     <APPLET> CODE = 'TicTacToe' WIDTH = 300 HEIGHT = 300 </APPLET>
    </CENTER>
     </BODY>
     </HTML>

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,419
    Rep Power
    25

    Default

    Does it work now? I never put blanks around the = in attributes.

  10. #10
    matejm1994 is offline Member
    Join Date
    Dec 2010
    Posts
    14
    Rep Power
    0

    Default

    No, it is not working.. yet :P

    Everything I see it is this picture.

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,419
    Rep Power
    25

    Default

    Go back and read posts #7 and #3

  12. #12
    matejm1994 is offline Member
    Join Date
    Dec 2010
    Posts
    14
    Rep Power
    0

    Default

    But...what can I do. There is no Error in java console, exept APPLET tag missing CODE parameter.

    Ok, I've got 2 files, both on my desktop.
    First: TicTacToe.class
    Second: TicTacToe.HTML
    And I also delete blanks round = in attributes. Probably is something wrong with path?

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,419
    Rep Power
    25

    Default

    exept APPLET tag missing CODE parameter
    that one is VERY important. The browser needs to see the code= attribute to find the starting class.


    Look again at your <APPLET tag. You show an extra/misplaced > just after the T. The ending > should be AFTER all of the attributes.

  14. #14
    matejm1994 is offline Member
    Join Date
    Dec 2010
    Posts
    14
    Rep Power
    0

    Default

    Hi,

    ok, now I repair the code. It is like this now:
    Java Code:
    <HTML>
     <HEAD>
    
     <TITLE>test</TITLE>
    
     <BODY>
     <CENTER>
     <APPLET CODE = 'TicTacToe' WIDTH = 300 HEIGHT = 300 ></APPLET>
    </CENTER>
     </BODY>
     </HTML>
    So, when I open it in browser, now there is nothing. And if I open console, there is this error. Do you think it could be something wrong with code in program?

    Java Code:
    Java Plug-in 1.6.0_24
    Using JRE version 1.6.0_24-b07 Java HotSpot(TM) Client VM
    User home directory = C:\Users\matejm1994
    ----------------------------------------------------
    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>
    ----------------------------------------------------
    java.lang.NoClassDefFoundError: TicTacToe (wrong name: Program/TicTacToe)
    	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: TicTacToe (wrong name: Program/TicTacToe)

  15. #15
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,240
    Rep Power
    19

    Default

    Evidently your TicTacToe.java starts with a package statement.

    db

  16. #16
    matejm1994 is offline Member
    Join Date
    Dec 2010
    Posts
    14
    Rep Power
    0

    Default

    Wow, thanks a lot!!!

    Now it is working, i have to remove package statement from code and now it is OK.
    Thanks!!

  17. #17
    s56ac is offline Member
    Join Date
    Jun 2011
    Posts
    1
    Rep Power
    0

    Default java problem

    HI !

    I have got another problem, too. I made an Java Applet, snake, nothing special. But when I try to upload it on web, it doesn't start. there is only white window.

    In the java console, there is this error:

    Java Code:
    Java Plug-in 1.6.0_25
    Using JRE version 1.6.0_25-b06 Java HotSpot(TM) Client VM
    User home directory = C:\Users\Armin
    ----------------------------------------------------
    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>
    ----------------------------------------------------
    java.security.AccessControlException: access denied (java.io.FilePermission C:/Users/Armin/Desktop/snake/screan.gif read)
    	at java.security.AccessControlContext.checkPermission(Unknown Source)
    	at java.security.AccessController.checkPermission(Unknown Source)
    	at java.lang.SecurityManager.checkPermission(Unknown Source)
    	at java.lang.SecurityManager.checkRead(Unknown Source)
    	at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
    	at sun.awt.SunToolkit.getImage(Unknown Source)
    	at javax.swing.ImageIcon.<init>(Unknown Source)
    	at javax.swing.ImageIcon.<init>(Unknown Source)
    	at snake.init(snake.java:60)
    	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Exception: java.security.AccessControlException: access denied (java.io.FilePermission C:/Users/Armin/Desktop/snake/screan.gif read)
    I believe that is something wrong with path for pictures. But I have no idea, how to fix it. The .html file is the same like one, which is some posts above. I think it is correct.

    thanks a lot !

    Armin

  18. #18
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,419
    Rep Power
    25

    Default

    access denied (java.io.FilePermission C:/Users/Armin/Desktop/snake/screan.gif read)
    Your applet does not have permission to read from the local disk.

    You should include all the files that the applet needs in a jar file with the applet's classes. Then use getResourceAsStream to get an InputStream that you can use to read the file.
    Do a search on the forum for getResource for many examples.

Similar Threads

  1. Crawl site, find new articles and then email HTML
    By africanhacker in forum New To Java
    Replies: 7
    Last Post: 03-30-2011, 11:26 PM
  2. Replies: 8
    Last Post: 03-10-2011, 07:00 PM
  3. Applet in Html
    By durduman in forum New To Java
    Replies: 10
    Last Post: 02-06-2011, 03:17 PM
  4. Replies: 6
    Last Post: 10-10-2008, 05:07 PM
  5. Replies: 0
    Last Post: 10-10-2008, 02:52 PM

Posting Permissions

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