Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  Slick2D applet blank screen + no errors.  (Read 1272 times)
0 Members and 1 Guest are viewing this topic.
Offline GhostID

Senior Newbie





« Posted 2013-05-08 02:54:49 »

I've been trying to figure out how to make an applet with Slick2D and I just can't seem to get it to work. I made a Main class and a Game class which extends BasicGame. The "game" runs perfectly on Eclipse, but when I compile it and launch it on a browser, it loads the content and shows a blank page after.

I posted the applet on my site as well as the FULL src to the project. Any help would be appreciated!

Applet: http://ghostid.net/games/applet_test/
Source: http://ghostid.net/external/downloads/Applet_TEST.zip

Here's all my code...

Main Class:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public class Main {
   public static void main(String[] args) {
      try {
         AppGameContainer game = new AppGameContainer(new Game("Test"));
         game.setDisplayMode(350, 250, false);
         game.start();
      } catch (SlickException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }
}


Game Class:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public class Game extends BasicGame {
   public Game(String title) {
      super(title);
      // TODO Auto-generated constructor stub
   }
   @Override
   public void render(GameContainer gc, Graphics g) throws SlickException {
      g.setColor(Color.red);
      g.fillRect(45, 45, 125, 100);
      g.setColor(Color.black);
      g.drawString("Hello. .__.", 60, 75);
   }
   @Override
   public void init(GameContainer gc) throws SlickException {   }
   @Override
   public void update(GameContainer gc, int ticks) throws SlickException { }
}


Here's my code for my HTML file.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
<applet code="org.lwjgl.util.applet.AppletLoader"
   archive="lwjgl_util_applet.jar, lzma.jar"
   codebase="." width="350" height="250">
   <param name="al_title" value="test">
   <param name="al_main" value="org.newdawn.slick.AppletGameContainer">
   <param name="game" value="net.ghostid.Main">
   <param name="al_jars" value="game.jar, slick.jar, lwjgl.jar.pack.lzma, jinput.jar.pack.lzma, lwjgl_util.jar.pack.lzma">
   <param name="al_windows" value="natives/windows_natives.jar.lzma">
   <param name="al_linux" value="natives/linux_natives.jar.lzma">
   <param name="al_mac" value="natives/macosx_natives.jar.lzma">
   <param name="al_solaris" value="natives/solaris_natives.jar.lzma">
   <param name="al_debug" value="true">
   <param name="separate_jvm" value="true">
   </applet>


Sorry for the sloppy code, tried making it as small as possible so this post wouldn't be insanely long.
So what's wrong? Why is my Applet just giving a white screen?

Thanks an advanced,
Once I get this working, I'll make a CLEAR tutorial on how to make a slick2d applet.. ._. I can't seem to find a full one with source code.
Offline xsvenson
« Reply #1 - Posted 2013-05-08 11:23:33 »

The "game" attribute should be the Game class, not the main class.
Use this instead:
<param name="game" value="net.ghostid.Game">

“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Offline GhostID

Senior Newbie





« Reply #2 - Posted 2013-05-09 03:58:51 »

I changed the engine a little and the game class is also the main now but it still doesn't work... Could you actually give me a working example?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline xsvenson
« Reply #3 - Posted 2013-05-09 23:57:56 »

http://www.planc.ee/m1sterx/zombify/

From the page source:

    <param name="al_main" value="org.newdawn.slick.AppletGameContainer">
    <param name="game" value="com.sxp.zombify.ZombifyClient">

1  
2  
3  
import org.newdawn.slick.BasicGame;
public class ZombifyClient extends BasicGame
{}

Note that this is the Game class, the main is a separate class.
Also, do You have java console running ? And You get no error there ?

“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Offline GhostID

Senior Newbie





« Reply #4 - Posted 2013-05-10 20:48:00 »

Quote
Note that this is the Game class, the main is a separate class.
Also, do You have java console running ? And You get no error there ?

Java console? It compiled on Eclipse and ran perfectly fine. Java didn't give a little red x on the top left of the screen so I suppose there is no errors. Anyway, I'll check out that example you gave me. Maybe it's just me being retarded. XD Thanks Smiley
Offline xsvenson
« Reply #5 - Posted 2013-05-10 20:50:41 »

Yes, Java Console. When You run an appplet or a webstart, then java starts the browser plugin which comes with the console. I believe, by default it's disabled.
Control Panel -> Java -> Advanced Tab -> Java Console -> enable
Check it out. It might tell You something new or might not. Assume nothing

“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Offline GhostID

Senior Newbie





« Reply #6 - Posted 2013-05-10 20:58:24 »

Hum, ok I did get an error.

Unable to create game container
java.lang.RuntimeException: Unable to create game container
   at org.newdawn.slick.AppletGameContainer.init(AppletGameContainer.java:147)
   at org.lwjgl.util.applet.AppletLoader.switchApplet(AppletLoader.java:1330)
   at org.lwjgl.util.applet.AppletLoader$2.run(AppletLoader.java:909)
   at java.awt.event.InvocationEvent.dispatch(Unknown Source)
   at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
   at java.awt.EventQueue.access$200(Unknown Source)
   at java.awt.EventQueue$3.run(Unknown Source)
   at java.awt.EventQueue$3.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)


And yes, I tried switching the game class to the game rather than the main and still got this error. Do I need to initialize the AppletGameContainer somewhere in my code? Set some settings (fps, window size etc...)?
Offline xsvenson
« Reply #7 - Posted 2013-05-12 22:12:29 »

Nope, You don't have to do anything with the applet container. However looking at the slick source, there should be more specific exception before the RuntimeException

“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Online kappa
« League of Dukes »

JGO Kernel


Medals: 81
Projects: 15


★★★★★


« Reply #8 - Posted 2013-05-12 23:32:37 »

1  
2  
3  
4  
5  
6  
public class Game extends BasicGame {
   public Game(String title) {
      super(title);
      // TODO Auto-generated constructor stub
   }
}


When using Slick Applets, the class that extends the BasicGame class can't have parameter(s) in the constructor otherwise Slick is unable to make a new instance of it.

Change 'public Game(String title)' to 'public Game()' and the above error should no longer happen.
Offline GhostID

Senior Newbie





« Reply #9 - Posted 2013-05-15 20:39:47 »

Thank you! Smiley Dude, this worked! I was expecting to have to do some ridiculous stuff xD
Thanks 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.

rwatson462 (37 views)
2014-12-15 09:26:44

Mr.CodeIt (30 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (59 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!