JME3 Nifty Button and TextField - Lightnet/openwizcoder GitHub Wiki

== Required skins and controls :==

<useStyles filename="nifty-default-styles.xml" />
<useControls filename="nifty-default-controls.xml" />

Those are needed to draw GUI. With out them it will display nothing on the screen.

==This section deal with text change:==

GUI XML file: This is Text field for GUI:

<control id="userid" width="128px" name="textfield" text="guest" />

ScreenController class

@NiftyEventSubscriber(id = "userid")
public void onUserNameChanged(final String id, final TextFieldChangedEvent event) {
     TextField score = event.getTextFieldControl();
     String username = event.getText();
     //System.out.print("text:"+username );
}

==Button Function:==

Button GUI XML file:

<control id="BtOptions" name="button" label="Options" />

ScreenController class

@NiftyEventSubscriber(id = "BtOptions")
public void BtOptionsClicked(final String id, final ButtonClickedEvent event) {
    System.out.print("\nButton press");
}

Basic code example check their main site.