Hey, me gain, the pain in the **** guy :D.
This is very probably my fault, but I’ve looked everywhere I could think of without finding a solution.
The lil test class here should show you my problem and provide a way of testing solutions (at least for me :D).
Basically:
- I initialize the screen
- I add a window to the screen with a button
- when I press the button, it tells me “first button was pressed” and then swaps the window (removes old window and adds the second window)
- once the second window is displayed, I press “space bar”… which triggers the first button… an element removed from the screen
Very probably my error, but could you tell me what I should do more in the swapMethod so that glitch doesn’t happen, please?
[java]
import com.jme3.app.FlyCamAppState;
import com.jme3.app.SimpleApplication;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.math.Vector2f;
import com.jme3.renderer.RenderManager;
import java.util.logging.Level;
import java.util.logging.Logger;
import tonegod.gui.controls.buttons.ButtonAdapter;
import tonegod.gui.controls.windows.Window;
import tonegod.gui.core.Screen;
/**
-
test
-
@author jo
*/
public class TestGuiCleaning extends SimpleApplication {private Screen screen;
public static void main(String[] args) {
TestGuiCleaning app = new TestGuiCleaning();
app.start();
}@Override
public void simpleInitApp() {
FlyCamAppState flyCamAppState = getStateManager().getState(FlyCamAppState.class);
flyCamAppState.setEnabled(false);initScreen(); firstScreen();
}
private void swapScreen(){
screen.removeElement(screen.getElementById(“firstScreen”));
secondScreen();
}private void firstScreen(){
Window window = new Window(screen, “firstScreen”, new Vector2f(100, 200));
window.setText(“First Screen”);
ButtonAdapter button = new ButtonAdapter(screen, “button01”, new Vector2f(20, 20)){
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
Logger.getLogger(TestGuiCleaning.class.getName()).log(Level.SEVERE, “First screen button pressed”);
swapScreen();
}
};
button.setText(“Click me”);
window.addChild(button);
screen.addElement(window);}
private void secondScreen(){
Window window = new Window(screen, “secondScreen”, new Vector2f(100, 200));
window.setText(“Second Screen”);
ButtonAdapter button = new ButtonAdapter(screen, “button02” ,new Vector2f(20, 20)){
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
Logger.getLogger(TestGuiCleaning.class.getName()).log(Level.SEVERE, “Second screen button pressed”);
}
};
button.setText(“Click me”);
window.addChild(button);
screen.addElement(window);}
private void initScreen() {
screen = new Screen(this);
// screen.initialize();
getGuiNode().addControl(screen);
screen.setUseToolTips(true);
}@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
}@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
[/java]