Slick2D applet blank screen + no errors.

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:


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:


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.


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

The “game” attribute should be the Game class, not the main class.
Use this instead:

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?

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

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 ?

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 :slight_smile:

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

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…)?

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

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.

Thank you! :slight_smile: Dude, this worked! I was expecting to have to do some ridiculous stuff xD
Thanks :slight_smile: