Setting up Slick 2D with netbeans 6.5.1


Slick2D engine is a high performance 2d game library based on a LWJGL(Lightweight Java Game Library). You can see the current features of Slick2D in their site. Download the library from here.
You can check the games made in Slick2D engine http://www.cokeandcode.com/ and http://slick.cokeandcode.com/gallery.php.

Tutorials : There are good and easy to go tutorials for beginners.

Now download the library. So here i’ll be telling how to setup the library with netbeans 6.5.1 so that u can write compile and run slick games easily and fast. I am using Ubuntu 8.04(Hardy heron), steps are similar for setting up in windows.

STEP 1: Download the library and save it in some appropriate place.
STEP 2: Open your Netbeans 6.5.1.
STEP 3: Go to tool->libraries. Library Manager window will open. Click New Library. Give it a name Slick. Then click OK.

screenshot-11

STEP 4: Now click classpath tab. Click Add Jar/Folder. Browse the folder where u have saved Your slick library. Go to lib folder and add all the jar files except slick.jar. Click OK

screenshot-2

STEP 5: Click JavaDoc tab. Click add/zip floder. Browse ur slick folder and select javadoc folder and add it. So done. Click OK.

screenshot-3

STEP 6: Ok so your slick library has been created. Now few steps remaining to complete the full set up. Create a new java project called SlickTest. Now Right Click SlickTest project, then click properties. Project properties window will open up. At left side, under categories select Libraries. Now at right side click Compile tab. Now Click Add Jar/Folder. Browse ur slick folder, go to lib folder, select slick.jar and add it.

screenshot-4

STEP 7: Now click Run tab. Click Add Library. Add Library window will open up. From there select Slick library that we previously created. Then add it.

screenshot-5

FINAL STEP 8 : Now at left side select Run. At Right side, go to VM Options, there u have to provide the parameter/argument that will link lwjgl libraries to your application. So at VM Options textbox, For Ubuntu users write: -Djava.library.path=lwjgl library path For Windows user write: -Djava.library.path=”lwjgl library path”. And Click Ok

Thats it Windows users have to put the path within double quotes. Here lwjgl library path is the path to the location where .so files for ubuntu linux(liblwjgl.so, liblwjgl64.so, libodejava.so,libopenal.so etc) and .dll for windows(liblwjgl.dll, liblwjgl64.dll, libodejava.dll,libopenal.dll etc) are located.

For windows user .dll files comes with slick library but linux users have to download the native .so lib files.

So now you are done and lets write a simple program for testing. This code will just create a window. Create a class called Test under the project that we had created.

package com.padam.testing;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

/**
*
* @author padam
*/
public class Test extends BasicGame{

public Test(String name){
super(name);
}

public static void main(String[] args){
try {
AppGameContainer container = new AppGameContainer(new Test(“Game”));
container.setDisplayMode(800,600,false);
container.start();
} catch (SlickException e) {
e.printStackTrace();
}
}

@Override
public void init(GameContainer gc) throws SlickException {

}

@Override
public void update(GameContainer gc, int delta) throws SlickException {

}

public void render(GameContainer gc, Graphics g) throws SlickException {

}

}

NOTE: Linux and Mac users must download the lwjgl library. Then browse the folder and go to native folder. There choose your native OS folder. That will be your lwjgl library path thatt will go to VM Options parameter as specified on last step or you can copy the .so/native files to your convenient location and provide that path to VM Options parameter.
Now after this just test the above code. You may get a runtime error saying:

Exception in thread “main” java.lang.LinkageError: Version mismatch: jar version is ‘16′, native libary version is ‘17′
at org.lwjgl.Sys.(Sys.java:105)
at org.lwjgl.opengl.Display.(Display.java:128)
at org.newdawn.slick.AppGameContainer$1.run(AppGameContainer.java:39)
at java.security.AccessController.doPrivileged(Native Method)
at org.newdawn.slick.AppGameContainer.(AppGameContainer.java:36)
at com.padam.testing.Test.main(Test.java:26)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

Linux/Mac/Solaris might face this problem because lwjgl jar files that comes with slick might be of older version which won’t match with the new lwjgl native .so/native files that u have downloaded. This means that the lwjgl jar files and lwjgl native/ .so files doesn’t match. So what u have to do is browse lwjgl folder that u have downloaded and go to jar folder and copy all the jar files and paste/replace the old jar files in the lib folder located in slick folder or location of slick library.

So Thats it. If u face any problem, comment it.

Gracias.


This entry was posted in Tutorials, developer and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

So far 1 views

11 Comments

  1. linux-mac-user
    Posted August 13, 2009 at 2:53 pm | Permalink

    Just extract native libraries from natives-mac.jar or natives-linux.jar they’re the version slick wants :)

  2. gilley
    Posted September 26, 2009 at 11:49 am | Permalink

    if anyone can help me get this sample code running i would much appreciate it thanks in advance. Ok B4 you flame me i should just let you know that i am new to java. when i read java code i can understand it and i can write it but when it comes to setting up the compiler am still learning.

    I followed the instructions on this website http://www.gaanza.com/blog/tag/slick-2d-with-netbeans/ on how to get slick and netBeans setup i am very confident that i followed the instructions down to a T and that slick is working.
    the problem am running into now is the last and final step, that is Step 8.
    It says to “Create a new java project called SlickTest”
    i did that, after i created the project i got a new editing window called Main.java
    and here is whats in it.

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package sllicktest;

    /**
    *
    * @author Chalise
    */
    public class Main {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    // TODO code application logic here
    }

    }

    then it says to create a class called Test i did that and the following is whats in it.

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author Chalise
    */
    public class Test {

    }

    Then they gave me the following code to test.

    package com.padam.testing;

    import org.newdawn.slick.AppGameContainer;
    import org.newdawn.slick.BasicGame;
    import org.newdawn.slick.GameContainer;
    import org.newdawn.slick.Graphics;
    import org.newdawn.slick.SlickException;

    /**
    *
    * @author padam
    */
    public class Test extends BasicGame{

    public Test(String name){
    super(name);
    }

    public static void main(String[] args){
    try {
    AppGameContainer container = new AppGameContainer(new Test(”Game”));
    container.setDisplayMode(800,600,false);
    container.start();
    } catch (SlickException e) {
    e.printStackTrace();
    }
    }

    @Override
    public void init(GameContainer gc) throws SlickException {

    }

    @Override
    public void update(GameContainer gc, int delta) throws SlickException {

    }

    public void render(GameContainer gc, Graphics g) throws SlickException {

    }

    }

    It doesn’t say to paste this code in Main.java or Test.java the class i just created. but i am assuming i have to paste the code inside my class and so here we go!

    package com.padam.testing;

    import org.newdawn.slick.AppGameContainer;
    import org.newdawn.slick.BasicGame;
    import org.newdawn.slick.GameContainer;
    import org.newdawn.slick.Graphics;
    import org.newdawn.slick.SlickException;

    /**
    *
    * @author padam
    */

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author Chalise
    */
    public class Test {

    public class Test extends BasicGame{

    public Test(String name){
    super(name);
    }

    public static void main(String[] args){
    try {
    AppGameContainer container = new AppGameContainer(new Test(“Game”));
    container.setDisplayMode(800,600,false);
    container.start();
    } catch (SlickException e) {
    e.printStackTrace();
    }
    }

    @Override
    public void init(GameContainer gc) throws SlickException {

    }

    @Override
    public void update(GameContainer gc, int delta) throws SlickException {

    }

    public void render(GameContainer gc, Graphics g) throws SlickException {

    }

    }

    }

    My problem lies here. when i try to build the program these are the errors i get.

    C:\Users\Chalise\Documents\NetBeansProjects\SllickTest\src\Test.java:25: com.padam.testing.Test is already defined in com.padam.testing
    public class Test extends BasicGame{
    C:\Users\Chalise\Documents\NetBeansProjects\SllickTest\src\Test.java:33: non-static variable this cannot be referenced from a static context
    AppGameContainer container = new AppGameContainer(new Test(“Game”));
    C:\Users\Chalise\Documents\NetBeansProjects\SllickTest\src\Test.java:31: inner classes cannot have static declarations
    public static void main(String[] args){
    3 errors
    BUILD FAILED (total time: 0 seconds)

    Does anybody have a clue as to what i need to do?

  3. Posted September 26, 2009 at 7:47 pm | Permalink

    Its a syntax error, you have written the code wrongly, check it properly.

    First Mistake: The first line of code is package com.padam.testing, but when u created the Test.java file then u didn’t provided that package name, u just simply left the package field empty. So omit this code from you file.

    Second Mistake: You have written the class Test class definition incorrectly. Watch it properly.
    public class Test {
    public class Test extends BasicGame{

    see u have defined the Test class twice(duplicate code), so correct it i.e remove public class Test { from the code and check for the extra braces(parenthesis) at the end.

    and Final Mistake: AppGameContainer container = new AppGameContainer(new Test(”Game”));
    watch this part closely new Test(”Game”)
    the string literal Game is not within the double quotes, yes when i pasted that on my netbeans efitor then that sign was different from double quotes as string literal are always wriiten within double quotes. So replace that sign with double quotes. Thats it.
    Now u can compile and run the code.

  4. gilley
    Posted September 29, 2009 at 4:20 pm | Permalink

    Thanks!
    Everything is fine now

  5. Brad
    Posted October 28, 2009 at 11:30 am | Permalink

    I need help with these errors as I can’t figure out what to do about this! it has been incredibly ANNOYING! PLEASE HELP
    import org.newdawn.slick.AppGameContainer;
    import org.newdawn.slick.BasicGame;
    import org.newdawn.slick.GameContainer;
    import org.newdawn.slick.Graphics;
    import org.newdawn.slick.SlickException;

    /**
    *
    * @author padam
    */
    public class Test extends BasicGame{

    public Test(String name){
    super(name);
    }

    public static void main(String[] args){
    try {
    AppGameContainer container = new AppGameContainer (new Test(“Game”));
    container.setDisplayMode(800,600,false);
    container.start();
    } catch (SlickException e) {
    e.printStackTrace();
    }
    }

    @Override
    public void init(GameContainer gc) throws SlickException {

    }

    @Override
    public void update(GameContainer gc, int delta) throws SlickException {

    }

    public void render(GameContainer gc, Graphics g) throws SlickException {

    }

    }
    this program returned the errors
    java.lang.NoClassDefFoundError: C:\Users\Boothe Family\Documents\bradley’s science\slick
    Caused by: java.lang.ClassNotFoundException: C:\Users\Boothe Family\Documents\bradley’s science\slick
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: C:\Users\Boothe Family\Documents\bradley’s science\slick. Program will exit.
    Exception in thread “main” Java Result: 1

  6. Posted October 29, 2009 at 4:37 am | Permalink

    well i tested the code that u have written and it is working perfectly.

    java.lang.NoClassDefFoundError generally occurs when the classpath is not set properly.

  7. Dave
    Posted February 5, 2010 at 9:20 am | Permalink

    I’ve tried to install Slick 2D in netbeans 6.7.1 and i get this error: Exception in thread “main” java.lang.LinkageError: Version mismatch: jar version is ‘16′, native libary version is ‘17′
    at org.lwjgl.Sys.(Sys.java:105)
    at org.lwjgl.opengl.Display.(Display.java:128)
    at org.newdawn.slick.AppGameContainer$1.run(AppGameContainer.java:39)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.newdawn.slick.AppGameContainer.(AppGameContainer.java:36)
    at slicktest.Test.main(Test.java:25)
    Java Result: 1

    Can u help me?

  8. Posted February 6, 2010 at 1:33 am | Permalink

    You need a matching lwjgl.jar and lwjgl.dll….
    it means that u r linking to new version of lwjgl.dll but ur using old lwjg.jar.
    U just replace the lwjgl.jar with latest jar version matching lwjgl.dll version.
    Gracias.

  9. Pedro
    Posted July 2, 2010 at 7:46 am | Permalink

    Hi.

    I did everything as you said.
    Now i’m trying this code:

    import java.awt.Graphics;
    import org.newdawn.slick.AppGameContainer;
    import org.newdawn.slick.BasicGame;
    import org.newdawn.slick.GameContainer;
    import org.newdawn.slick.SlickException;

    public class Main extends BasicGame{

    public Main(String name){
    super(name);
    }

    public static void main(String[] args){
    try {
    AppGameContainer container = new AppGameContainer(new Main(“Game”));
    container.setDisplayMode(800,600,false);
    container.start();
    } catch (SlickException e) {
    e.printStackTrace();
    }
    }

    @Override
    public void init(GameContainer gc) throws SlickException {

    }

    @Override
    public void update(GameContainer gc, int delta) throws SlickException {

    }

    public void render(GameContainer gc, Graphics g) throws SlickException {

    }

    public void render(GameContainer gc, org.newdawn.slick.Graphics grphcs) throws SlickException {
    throw new UnsupportedOperationException(“Not supported yet.”);
    }

    }

    And it gives me this error:

    java.lang.NoClassDefFoundError: library
    Caused by: java.lang.ClassNotFoundException: library
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    Could not find the main class: library. Program will exit.
    Exception in thread “main” Java Result: 1

    I checked if i added all jars/folders correctly and i did.

    Thanks for any help!

  10. Pedro
    Posted July 2, 2010 at 8:09 am | Permalink

    Ok it seems that the problem was the “” characters that i copied from your blog.
    But now it’s giving me this errors:

    Fri Jul 02 03:38:43 BST 2010 INFO:Slick Build #274
    Fri Jul 02 03:38:43 BST 2010 INFO:LWJGL Version: 2.0b1
    Fri Jul 02 03:38:43 BST 2010 INFO:OriginalDisplayMode: 1280 x 1024 x 32 @75Hz
    Fri Jul 02 03:38:43 BST 2010 INFO:TargetDisplayMode: 800 x 600 x 0 @0Hz
    Fri Jul 02 03:38:43 BST 2010 INFO:Starting display 800×600
    Fri Jul 02 03:38:43 BST 2010 INFO:Use Java PNG Loader = true
    WARNING: Found unknown Windows version: Windows 7
    Attempting to use default windows plug-in.
    Fri Jul 02 03:38:43 BST 2010 INFO:Found 6 controllers
    Fri Jul 02 03:38:43 BST 2010 INFO:0 : MP-8800 Quad USB Joypad
    Fri Jul 02 03:38:43 BST 2010 INFO:1 : MP-8800 Quad USB Joypad
    Fri Jul 02 03:38:43 BST 2010 INFO:2 : MP-8800 Quad USB Joypad
    Fri Jul 02 03:38:43 BST 2010 INFO:3 : MP-8800 Quad USB Joypad
    Fri Jul 02 03:38:43 BST 2010 INFO:4 : USB Sound Device
    Fri Jul 02 03:38:43 BST 2010 INFO:5 : G3
    Fri Jul 02 03:38:43 BST 2010 ERROR:Not supported yet.
    java.lang.UnsupportedOperationException: Not supported yet.
    at pokemonworld.Main.render(Main.java:40)
    at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:681)
    at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:408)
    at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318)
    at pokemonworld.Main.main(Main.java:19)
    Fri Jul 02 03:38:43 BST 2010 ERROR:Game.render() failure – check the game code.
    org.newdawn.slick.SlickException: Game.render() failure – check the game code.
    at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:684)
    at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:408)
    at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318)
    at pokemonworld.Main.main(Main.java:19)

    What am i doing wrong here?

  11. Posted July 9, 2010 at 8:04 pm | Permalink

    okie. i tested ur code, its creating error because u have written codes wrongly.

    Acording to your code u have written two render methods, first render method takes awt.Graphics as parameter and other render() takes org.newdawn.slick.Graphics.

    so u are not to use render() which is taking awt.Graphics.

    so here is the code again:

    import org.newdawn.slick.AppGameContainer;
    import org.newdawn.slick.BasicGame;
    import org.newdawn.slick.GameContainer;
    import org.newdawn.slick.SlickException;
    import org.newdawn.slick.Graphics;

    public class Main extends BasicGame{

    public Main(String name){
    super(name);
    }

    public static void main(String[] args){
    try {
    AppGameContainer container = new AppGameContainer(new Main(“Game”));
    container.setDisplayMode(800,600,false);
    container.start();
    } catch (SlickException e) {
    e.printStackTrace();
    }
    }

    @Override
    public void init(GameContainer gc) throws SlickException {

    }

    @Override
    public void update(GameContainer gc, int delta) throws SlickException {

    }

    public void render(GameContainer gc, Graphics g) throws SlickException {

    }

    }

    see public void render(GameContainer gc, Graphics g) throws SlickException{}
    here Graphics class is org.newdawn.slick.Graphics, not java.awt.Graphics. So u shouln’t have imported awt package. This is not java 2D. I hope it helped u.

    Gracias.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

  • Become a GaanZa Fan

    GaanZa on Facebook