Results 1 to 18 of 18
Thread: How to add Applet in HTML site
- 06-07-2011, 06:42 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 14
- Rep Power
- 0
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>
- 06-07-2011, 06:54 PM #2
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!
- 06-07-2011, 08:06 PM #3
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 >
- 06-07-2011, 08:18 PM #4
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 06-07-2011, 08:20 PM #5
Yeah, these forums are great for that.
- 06-07-2011, 09:02 PM #6
Member
- Join Date
- Dec 2010
- Posts
- 14
- Rep Power
- 0
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.
- 06-07-2011, 09:41 PM #7
See the second line of post #3
What is in the Java Console?
- 06-07-2011, 09:55 PM #8
Member
- Join Date
- Dec 2010
- Posts
- 14
- Rep Power
- 0
Hi,
so, if I open Java Console, there id this:
And I repair the HTML Code. Now it is like that: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.
Java Code:<HTML> <HEAD> <TITLE>test</TITLE> <BODY> <CENTER> <APPLET> CODE = 'TicTacToe' WIDTH = 300 HEIGHT = 300 </APPLET> </CENTER> </BODY> </HTML>
- 06-07-2011, 09:57 PM #9
Does it work now? I never put blanks around the = in attributes.
- 06-07-2011, 10:01 PM #10
Member
- Join Date
- Dec 2010
- Posts
- 14
- Rep Power
- 0
No, it is not working.. yet :P
Everything I see it is this picture.
- 06-07-2011, 10:05 PM #11
Go back and read posts #7 and #3
- 06-07-2011, 10:24 PM #12
Member
- Join Date
- Dec 2010
- Posts
- 14
- Rep Power
- 0
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?
- 06-07-2011, 10:31 PM #13
that one is VERY important. The browser needs to see the code= attribute to find the starting class.exept APPLET tag missing CODE parameter
Look again at your <APPLET tag. You show an extra/misplaced > just after the T. The ending > should be AFTER all of the attributes.
- 06-08-2011, 08:06 AM #14
Member
- Join Date
- Dec 2010
- Posts
- 14
- Rep Power
- 0
Hi,
ok, now I repair the code. It is like this now: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:<HTML> <HEAD> <TITLE>test</TITLE> <BODY> <CENTER> <APPLET CODE = 'TicTacToe' WIDTH = 300 HEIGHT = 300 ></APPLET> </CENTER> </BODY> </HTML>
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)
- 06-08-2011, 08:12 AM #15
Evidently your TicTacToe.java starts with a package statement.
db
- 06-08-2011, 08:36 AM #16
Member
- Join Date
- Dec 2010
- Posts
- 14
- Rep Power
- 0
Wow, thanks a lot!!!
Now it is working, i have to remove package statement from code and now it is OK.
Thanks!!
- 06-08-2011, 09:07 PM #17
Member
- Join Date
- Jun 2011
- Posts
- 1
- Rep Power
- 0
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:
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.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)
thanks a lot !
Armin
- 06-08-2011, 10:34 PM #18
Your applet does not have permission to read from the local disk.access denied (java.io.FilePermission C:/Users/Armin/Desktop/snake/screan.gif read)
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
-
Crawl site, find new articles and then email HTML
By africanhacker in forum New To JavaReplies: 7Last Post: 03-30-2011, 11:26 PM -
java applet on remote site runs in browser, but fails when opened locally
By Albrecht in forum Java AppletsReplies: 8Last Post: 03-10-2011, 07:00 PM -
Applet in Html
By durduman in forum New To JavaReplies: 10Last Post: 02-06-2011, 03:17 PM -
java: xml/html file with doctype trying to connect to site
By newbieal in forum New To JavaReplies: 6Last Post: 10-10-2008, 05:07 PM -
java: xml/html file with doctype trying to connect to site
By newbieal in forum New To JavaReplies: 0Last Post: 10-10-2008, 02:52 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks