LoadingScreen What Am I Doing Wrong?

The book says:

"We began by creating a new class called LoadingScreenController that extends the Controller class. We
define two Strings: loadingText and loadingScreen. And create setters for these as well. Next we override the onStartScreen() method and add the following three lines of code:

screen.findElementByName("centralPanel").getRenderer(ImageRenderer.class).setImage(nifty.createImage(loadingScreen, true));

The book says:

"First we need to add the screen to Nifty. If we have the NiftyAppState method from the previous recipe, we should add the following line just after the nifty.fromXml call:
"We can also add a convenience class to access nifty.gotoScreen()

The book says:
"Before calling gotoScreen("loadingScreen") from our main class, we can add the following lines to set loadingText and loadingImage…Now where do I put this code at??? I’m Confused from what the book is telling me…

((LoadingScreenController)niftyState.getNifty().getScreen("loadingScreen").getScreenController()).setLoadingText("Loading Test Scene");((LoadingScreenController)niftyState.getNifty().getScreen("loadingScreen").getScreenController()).setLoadingImage("Interface/loadingScreen.png");

Now here is my code for LoadingScreenController class:

import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.control.Control;
import java.io.IOException;
import de.lessvoid.nifty.elements.render.ImageRenderer;
import de.lessvoid.nifty.controls.Label;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.Nifty;

public class LoadingScreenController extends Controller { //error LoadingScreenController not abstract
   public void onStartScreen(Screen screen, Nifty nifty, String loadingText, String loadingScreen) {
        screen.findNiftyControl("caption", Label.class).setText(loadingText);
                .setImage(nifty.createImage(loadingScreen, true));

Controller class…

import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.niftygui.NiftyJmeDisplay;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.controls.Console;
import de.lessvoid.nifty.screen.ScreenController;

abstract public class Controller extends SimpleApplication implements ScreenController { 

    protected NiftyJmeDisplay niftDisplay;
    protected Screen screen;
    Nifty nifty;
    Console console;
    boolean optionsMenuVisible = false;

    public static void main(String[] args){

    public void bind(Nifty nifty, Screen screen) {
        System.out.println("bind( " + screen.getScreenId() + ")");
        nifty.getScreen("main").findNiftyControl("console", Console.class);
    public void outputToConsole(String input){
    public void toggleConsole(){
        //page 339
    public void onConsoleCommand(final String id){
        //page 339
    public void toggleOptionsMenu(){

    public void onStartScreen() {

    public void onEndScreen() {

    public void quit(Controller app){


And lastly my NiftyAppState class…

import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.asset.AssetManager;
import com.jme3.niftygui.NiftyJmeDisplay;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.asset.AssetManager;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import de.lessvoid.nifty.screen.ScreenController;
import de.lessvoid.nifty.Nifty;
import com.jme3.renderer.ViewPort;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.controls.Parameters;
import com.jme3.input.InputManager;
import com.jme3.audio.AudioRenderer;

public class NiftyAppState extends AbstractAppState implements ActionListener {
    private Nifty nifty;
    private NiftyJmeDisplay niftDisplay;
    private InputManager inputManager;
    private AssetManager assetManager;
    private ViewPort guiViewPort;
    private AudioRenderer audioRenderer;
    public static void main(String[]args){
    public void simpleInitApp() {
        niftDisplay = new NiftyJmeDisplay(assetManager,
        nifty = niftDisplay.getNifty();
    public void initialize(AppStateManager stateManager, Application app) {
        super.initialize(stateManager, app);
        NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(
        app.getAssetManager(), app.getInputManager(), app.getAudioRenderer(),
        app.getRenderManager().getPostView("Gui Default"));
        app.getRenderManager().getPostView("Gui Default")
        app.getInputManager().addMapping("TOGGLE_OPTIONS", new KeyTrigger
        app.getInputManager().addListener(this, "TOGGLE_OPTIONS");
        //TODO: initialize your AppState, e.g. attach spatials to rootNode
        //this is called on the OpenGL thread after the AppState has been attached
    public void onAction(String name, boolean isPressed, float tpf){
        if(name.equals("TOGGLE_OPTIONS") && isPressed){

Help me put this in order

I’m sorry but I must of inserted the ticks wrong into the code causing all of my topic to come out as code. Sorry guys I’m frustrated that I have to type from a book to get my message across. The book is super ridiculous and misleading. its the cookbook and I’m just lost on which class I insert code into. I know what a field is and I know what a method is. I just don’t know what the freaking book wants from me

This path you are on is going to be extremely difficult unless you already know Java pretty well. You can continue like you are, of course… but be prepared to struggle every step of the way.

Learning Java is tough. Learning game programming is tough. Learning 3D game programming is super tough. Doing all three at once is like learning to shave while learning to ride a bike with no hands… prepare to lose parts of your face.


Thanks for the heads up

Hey I have a serious question though. What is a convenience class? The thing you add before the gotoScreen method

It can be whatever, but probably a small class that helps you by not needing to type the same code every time. Utility class is probably similar. But these are just common terms used by coders. They are what you make of them. Convenience class has no meaning in Java.

Have you tried first to look the JME SDK and its demos? It is ready code you can study and change and see the results immediately. It feels to me that that would perhaps be more easier starting point… I also own the books (Cookbook and the Beginners guide?) and I think they’re ok. Somethings are obsolete already though. But if the code is really that broken… better start with working code.

…which brings up an important point. Which book are you working from?

The beginners guide should be pretty complete, I guess… the cookbook is for more advanced users that already know Java pretty well.

“main class” here is referring to the Application class, perhaps a bit unclear. In the code package that would be TestLoadingScreen.
I am sure everything will be much easier if you follow the code while doing the recipes.

Yeah you got a point there. I’ve been running through tutorials again and practicing. I’ll be getting well