Input Issue

I have several GameStateNodes that each have their own JMEDesktop and various UI components added to them. In the first state, MainMenu, I have a JTextField. It works pefectly except for the fact that the input to the field is multiplied times the number of GameStateNodes I have instantiated. So if I type the letter 'a', 3 letter a's will appear, one for each GameStateNode I've got. Mind you, the states don't have to currently be active, just created. The other point of interest is that all the GameStateNodes share the same input handler (although I shouldn't think that matters).



My MenuState class is very simply:


/*
 * Created on Feb 1, 2005
 */

package imp.gui;

import java.awt.Color;

import com.jme.app.GameStateNode;
import com.jmex.awt.swingui.JMEDesktop;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.system.DisplaySystem;

import imp.Imp;
import com.jme.scene.state.LightState;

/**
 * @author scott
 */
public abstract class MenuState extends GameStateNode {

I was unaware that all JMEDesktops receive all events no matter what their state, but I guess that makes sense.



So what I was able to do to get it to stop sending events (and fix my bug) was to add a conditional to sendAWTKeyEvent in JMEDesktop:



if (getFocusOwner().getFocusCycleRootAncestor() == desktop){

handle the event

}



I'm not really an expert on UI's, so I may be way off-base, but it seems like other JMEDesktops should not be dealing with components that are not their own. Any thoughts?

Slowdive said:

The other point of interest is that all the GameStateNodes share the same input handler (although I shouldn't think that matters).

That's exactly the problem - disable the input handler of all inactive JMEDesktops.

Ack, but what if they all share the same one? At points I will have two JMEDesktops active and want both to work with the same handler.

Slowdive said:

Ack, but what if they all share the same one?

They don't  :P

Each JMEDesktop creates it's own input handler and registers it with the one you specify in the ctor. Simply do myDesktop1.getInputHandler().setEnabled( true/false ) to enable/disable it. Multiple JMEDesktop at once are not supported yet :|

Okie doke. In that case I guess I switch to all one desktop then. Thanks for the info!