Regenuluz
Jr. Member   Posts: 73 Medals: 1
|
 |
«
on:
2012-01-14 07:59:50 » |
|
Mkay, So I've been trying to port the Tetris game I made for class into an Applet, so that I could show it to people without them having to download and run the Jar file. But no matter how I try and pack the Jar file and run the applet I keep getting "java.lang.ClassNotFoundException: Game.class" as an error. The html code I use to try and get it running is: 1 2 3 4
| <applet code="Game.class" archive="Tetris.jar" width="120" height="120"> </applet> |
(Yeah, very small dimension, but I'll change that once it's actually fricking running :/) And the Manifest.txt for the Jar file is: I've also tried naming it just "Game" in both the manifest and the html. Just changes the error to be without .class in the end. The Game.java file contains: 1 2 3 4 5 6 7 8 9 10 11 12
| import javax.swing.JApplet;
import Model.Tetris; import Model.Tetris6_2;
public class Game extends JApplet {
public void init() { Tetris ts = new Tetris6_2(); ts.startGame(10, 20); } } |
The Jar file runs perfectly when the Game.java file is changed to: 1 2 3 4 5 6 7 8 9 10
| import Model.Tetris; import Model.Tetris6_2;
public class Game {
public static void main(String[] args) { Tetris ts = new Tetris6_2(); ts.startGame(10, 20); } } |
Any help with making this stupid Tetris game run as an Applet would be greatly appreciated! 
|
|
|
|
|
ReBirth
JGO Wizard     Posts: 1275 Medals: 19
|
 |
«
Reply #1 on:
2012-01-14 08:14:51 » |
|
You put the html and jar at same folder then execute the html right? IMO manifest doesn't named like that (Manifest.txt). Refer to java doc again.
|
|
|
|
Regenuluz
Jr. Member   Posts: 73 Medals: 1
|
 |
«
Reply #2 on:
2012-01-14 09:19:45 » |
|
Yes, I put it in the same folder. And according to the java docs, that's exactly how to create a manifest file. Like I said, if I change it so that it's a standalone app, then the jar file works.
|
|
|
|
|
Games published by our own members! Go get 'em!
|
|
|
|
Regenuluz
Jr. Member   Posts: 73 Medals: 1
|
 |
«
Reply #4 on:
2012-01-14 09:42:12 » |
|
Which I am doing. 
|
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5870 Medals: 255
Hand over your head.
|
 |
«
Reply #5 on:
2012-01-14 10:14:08 » |
|
Which I am doing.   Oops. Anyway, this: 1 2 3 4
| <applet code="Game.class" archive="Tetris.jar" width="120" height="120"> </applet> |
makes the classloader search for a class called "Game.class", which obviously is a filename, not a classname. 1 2 3 4 5
| <applet code="my.package.MyClass" <-- note there is no ".class" archive="Tetris.jar" width="120" height="120"> <PARAM name="codebase_lookup" value="false"> <-- also prevent the classloader from fetching "./my/package/MyClass.class" over HTTP </applet> |
That would do the job. It's how the applets in JGO are embedded. If that doesn't work, maybe "Tetris.jar" is not in the directory you think it is, or it is actually named "tetris.jar" (case sensitive). It might also mean the package is mandatory, you currently did not put the class in a package.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
Regenuluz
Jr. Member   Posts: 73 Medals: 1
|
 |
«
Reply #6 on:
2012-01-15 09:16:59 » |
|
I'm still not having any luck, no matter what I do. When I run the game from Eclipse it's running the applet without any problems. I even tried using Eclipse to port it as a jar file for me, still no luck. Moved Game.java from the "root" to a package, and still no luck. :/ The structure of my jar file is: 1 2 3 4 5
| Controller/ META-INF/ Model/ View/ Game.class |
and it's in the same directory as my html page. :/
|
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5870 Medals: 255
Hand over your head.
|
 |
«
Reply #7 on:
2012-01-15 09:18:33 » |
|
why not put it online and post the link? then we can make informed suggestions.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
Regenuluz
Jr. Member   Posts: 73 Medals: 1
|
 |
«
Reply #8 on:
2012-01-16 03:15:02 » |
|
Alright, it can be found here: http://infloop.org/tmp/tetris/ (It's still not working, and I really haven't got a clue as to why it's not working. :/ ) It was far easier to get my minesweeper to work! (Made in html/javascript http://infloop.org/tmp/minesweeper/ for those who wants to see it xD)
|
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5870 Medals: 255
Hand over your head.
|
 |
«
Reply #9 on:
2012-01-16 03:28:42 » |
|
Class is loaded just fine. The console says this: 1 2 3 4 5 6 7 8 9 10 11 12
| java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0) 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.checkExit(Unknown Source) at javax.swing.JFrame.setDefaultCloseOperation(Unknown Source) at View.GameWindow.<init>(GameWindow.java:23) at Model.Tetris6_2.startGame(Tetris6_2.java:43) at Game.init(Game.java:12) at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Exception: java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0) |
So, do not use: javax.swing.JFrame.setDefaultCloseOperation(EXIT_ON_CLOSE)as that is not allowed in the security sandbox.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
Games published by our own members! Go get 'em!
|
|
Regenuluz
Jr. Member   Posts: 73 Medals: 1
|
 |
«
Reply #10 on:
2012-01-16 03:38:39 » |
|
How come I never saw that error? :/ I blame Chrome.
Now I just need it to not open up in a weird new window when it starts. Probably need to change it from JFrame?
|
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5870 Medals: 255
Hand over your head.
|
 |
«
Reply #11 on:
2012-01-16 03:46:48 » |
|
How come I never saw that error? :/ I blame Chrome.
I use Chrome. Now I just need it to not open up in a weird new window when it starts. Probably need to change it from JFrame?
Well, that's the whole point in coding your game in an Applet, as opposed to using an Applet to kickstart a JFrame. Look at the 'getting started' link I posted earlier for a proper tutorial.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
Regenuluz
Jr. Member   Posts: 73 Medals: 1
|
 |
«
Reply #12 on:
2012-01-16 03:48:41 » |
|
Hrm, I didn't see it in the console. Oh well.  What should I use instead of a JFrame? Just a JPanel? (I'll try it out with that now)
|
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5870 Medals: 255
Hand over your head.
|
 |
«
Reply #13 on:
2012-01-16 03:49:33 » |
|
Look at the 'getting started' link I posted earlier for a proper tutorial.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
Regenuluz
Jr. Member   Posts: 73 Medals: 1
|
 |
«
Reply #14 on:
2012-01-16 03:58:51 » |
|
Hrm, it seems that I can't use getBufferStrategy() with a Canvas? Guess I'll have to go through the guide more throughly(sp?). But thanks a bunch so far! 
|
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5870 Medals: 255
Hand over your head.
|
 |
«
Reply #15 on:
2012-01-16 04:01:34 » |
|
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
Regenuluz
Jr. Member   Posts: 73 Medals: 1
|
 |
«
Reply #16 on:
2012-01-16 04:08:09 » |
|
That's what I did. I got this error: 1
| java.lang.IllegalStateException: Component must have a valid peer |
|
|
|
|
|
ra4king
JGO Kernel      Posts: 3158 Medals: 196
I'm the King!
|
 |
«
Reply #17 on:
2012-01-16 04:23:39 » |
|
You can only call that method after you have added the Canvas in the init() method 
|
|
|
|
Regenuluz
Jr. Member   Posts: 73 Medals: 1
|
 |
«
Reply #18 on:
2012-01-16 04:26:52 » |
|
oooh  Just rearranged 2 lines and now it works! Awesome! Just need to set the size of the window now xD Thanks a bunch 
|
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5870 Medals: 255
Hand over your head.
|
 |
«
Reply #19 on:
2012-01-16 05:10:58 » |
|
You can only call that method after you have added the Canvas in the init() method  Please consider that Applet.init(), Applet.start(), Applet.stop() and Applet.destroy() are not executed on the EventDispatchThread. Adding components (or making any other changes to UI components) is therefore highly discouraged as issues can be hard to reproduce and/or fix.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
|
|
ra4king
JGO Kernel      Posts: 3158 Medals: 196
I'm the King!
|
 |
«
Reply #21 on:
2012-01-16 05:23:50 » |
|
Works for me. @Riven, it shouldn't be much of a problem when "init"-ing the UI however. Modifying the UI in any other method Applet life-cycle method is discouraged yes 
|
|
|
|
|