Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (116)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Making an applet run? (solved)  (Read 1677 times)
0 Members and 1 Guest are viewing this topic.
Offline Regenuluz
« Posted 2012-01-14 12: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:
1  
Main-Class: Game.class


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! Smiley
Offline ReBirth
« Reply #1 - Posted 2012-01-14 13: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.

Offline Regenuluz
« Reply #2 - Posted 2012-01-14 14: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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 800
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2012-01-14 14:22:12 »

Applets are deployed radically different from applications. There is no 'main class' with a main-method. You have to extend the Applet class:

http://docs.oracle.com/javase/tutorial/deployment/applet/getStarted.html

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Regenuluz
« Reply #4 - Posted 2012-01-14 14:42:12 »

Which I am doing. Smiley
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 800
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2012-01-14 15:14:08 »

Which I am doing. Smiley
Lips Sealed 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
Offline Regenuluz
« Reply #6 - Posted 2012-01-15 14: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. :/
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 800
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2012-01-15 14: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
Offline Regenuluz
« Reply #8 - Posted 2012-01-16 08: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 Tongue http://infloop.org/tmp/minesweeper/ for those who wants to see it xD)
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 800
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2012-01-16 08: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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Regenuluz
« Reply #10 - Posted 2012-01-16 08: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?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 800
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2012-01-16 08: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
Offline Regenuluz
« Reply #12 - Posted 2012-01-16 08:48:41 »

Hrm, I didn't see it in the console. Oh well. Smiley

What should I use instead of a JFrame? Just a JPanel? (I'll try it out with that now)
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 800
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #13 - Posted 2012-01-16 08: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
Offline Regenuluz
« Reply #14 - Posted 2012-01-16 08: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! Cheesy
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 800
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #15 - Posted 2012-01-16 09:01:34 »

http://docs.oracle.com/javase/6/docs/api/java/awt/Canvas.html#getBufferStrategy()

Just add the canvas to the applet.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Regenuluz
« Reply #16 - Posted 2012-01-16 09:08:09 »

That's what I did. I got this error:
1  
java.lang.IllegalStateException: Component must have a valid peer
Offline ra4king

JGO Kernel


Medals: 346
Projects: 3
Exp: 5 years


I'm the King!


« Reply #17 - Posted 2012-01-16 09:23:39 »

You can only call that method after you have added the Canvas in the init() method Wink

Offline Regenuluz
« Reply #18 - Posted 2012-01-16 09:26:52 »

oooh Tongue Just rearranged 2 lines and now it works! Awesome! Just need to set the size of the window now xD

Thanks a bunch Smiley
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 800
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #19 - Posted 2012-01-16 10:10:58 »

You can only call that method after you have added the Canvas in the init() method Wink
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
Offline Regenuluz
« Reply #20 - Posted 2012-01-16 10:21:10 »

It's now working! Yay! Playable version right here: http://infloop.org/tmp/tetris/ Smiley

Thanks for the help guys!
Offline ra4king

JGO Kernel


Medals: 346
Projects: 3
Exp: 5 years


I'm the King!


« Reply #21 - Posted 2012-01-16 10: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 Smiley

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (30 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (28 views)
2014-09-20 20:14:06

BurntPizza (32 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!