I created a Hello World for you, but I already know what was your problem. In the class where you extended TWLStateBasedGame your getThemeURL() method is wrong. It gives back null. Which is because it can't find a theme. Your path is propably wrong there.
these are the libs you need:
slick.jar
twl.jar
lwjgl.jar with natives
xpp3-1.1.4c.jar
resources you need and your project was missing these:
A theme.xml which describe the GUI. In the example I put this into the resources package.
You also need the classes in the TWLSlick.zip
Here are my classes:
Main.java:
Code:
package main;
import java.net.URL;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
public class Main extends TWLStateBasedGame {
protected Main() {
super("HelloSlickTWL");
}
public static void main(String[] args) {
try {
AppGameContainer app = new AppGameContainer(new Main());
app.setTargetFrameRate(60);
app.setMaximumLogicUpdateInterval(16);
app.setMinimumLogicUpdateInterval(16);
app.setDisplayMode(600,600,false);
app.start();
} catch (SlickException e) {
e.printStackTrace();
}
}
@Override
protected URL getThemeURL() {
return Main.class.getResource("/resource/theme.xml");
}
@Override
public void initStatesList(GameContainer arg0) throws SlickException {
addState(new HelloState());
}
}
HelloState.java:
Code:
package main;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;
import de.matthiasmann.twl.Button;
public class HelloState extends BasicTWLGameState {
@Override
public int getID() {
return 1;
}
@Override
public void enter(GameContainer container, StateBasedGame game)
throws SlickException {
super.enter(container, game);
Button btn = new Button("Hello world");
btn.setSize(100,50);
btn.setPosition(300, 300);
btn.addCallback(new Runnable() {
@Override
public void run() {
System.out.println("Hello Slick world! This button works!");
}
});
rootPane.add(btn);
}
@Override
public void init(GameContainer container, StateBasedGame game)
throws SlickException {}
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g)
throws SlickException {}
@Override
public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException {}
}
The Main.java have a method called getTheme() where it loads the resource. Your path there is probably wrong.
The wiki on TWL suggest to override the createRootPane() method. That wiki article is wrong, because you can't do that. You can't do it because the return type of createRootPane() is void not RootPane. So don't pay attention to that. Also enterState() automatically calls createRootPane() if you don't override it.