[Solved]Nifty Button. How to Quit App?

For some reason I can not figure out how to quit the app using Nifty.

I have a MenuAppState that extends AbstractAppState and implements (Nifty) Controller

I have a Nifty xml

<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd">
    <useStyles filename="nifty-default-styles.xml" />
    <useControls filename="nifty-default-controls.xml" />
    <screen id="start" >
        <layer id="layer" backgroundColor="#003f" childLayout="center" controller="mygame.MenuAppState">
            <panel id="panel" height="25%" width="35%" align="center" valign="center" backgroundColor="#f60f" childLayout="center" visibleToMouse="true">
                <control name="button" label="Quit" id="QuitButton" align="center" valign="center" >
                    <interact onClick="quitIt()"/>
                </control>                
            </panel>
        </layer>
    </screen>
</nifty>

In the MenuAppState I have

 public void initialize(AppStateManager stateManager, Application app) {
        super.initialize(stateManager, app);
        rootApp = (Main) app;

public void quitIt() {
    System.out.println("quitIt()");
    nifty.exit();
    rootApp.stop();
}

I see the output quitIt() in the console so I know it is firing but the app remains running.

Thanks for any help.
-Greg

try that:

 public void initialize(AppStateManager stateManager, Application app) {
        super.initialize(stateManager, app);
        rootApp = app;

public void quitIt() {
    System.out.println("quitIt()");
    nifty.exit();
    rootApp.stop();
}

btw: I strongly advice you to use an other gui other than Nifty ( nifty is too old) example: Lemur and tonegodgui

I don’t see a reason suggesting Nifty being “too old”.

well nifty is very hard to use , and almost nobody use it anymore :smiley:

Nifty just got updated to 1.4.1 in jmonkey 3.1 and nifty 2.0 is coming up soon, so its still being actively developed. It is a bit hard to use, and lemur and tonegodgui are great. Tonegodgui has not been maintained in the last ~4 months though.

^ So if you want to save up time and if you are new then you should use an other gui :smiley: but that doesn’t mean that nifty gui is bad

I don’ think thats correct.

Maybe it’s easy for you as you are not a beginner in java and jme3 but for me I find it somehow , har :smiley:

I was referring to the “nobody uses it anymore”. The other point is subjective.

Ooh there might be some people who still uses it , but I think most of them love to use their own gui or an easy to use gui

I don’t think thats correct.

Well No one knows the truth :slight_smile:

I figured it out. I was not calling Nifty Correctly

I was using

  this.nifty.fromXml("Interface/menuGUI.xml", "start");

instead of

  this.nifty.fromXml("Interface/menuGUI.xml", "start", this);  //<----- Notice the "this"

…
public class MenuAppState extends AbstractAppState implements ScreenController

Since my MenuAppState was doing the implements Controller but was not being used.
The MenuAppState instance that was being called was not the same instance that I created in my code
In my quit() method rootApp was null and was throwing a null pointer exception that was being eaten by Nifty.

-Greg

…the most evil of programming evils…

1 Like