RIght now I have a UI which is a text area and when I type text into any keys which I catch for my main window still affect the main window.
In the main program I do …
Toolkit.getDefaultToolkit().addAWTEventListener(new KeyboardEventListener(keyEventList),AWTEvent.KEY_EVENT_MASK);
For the overlay I do
UIEventAdapter eventAdapter = new UIEventAdapter(windowMgr);
canvas.get3DPeer().getComponent().addKeyListener(eventAdapter);
canvas.get3DPeer().getComponent().addMouseListener(eventAdapter);
canvas.get3DPeer().getComponent().addMouseMotionListener(eventAdapter);
canvas.get3DPeer().getComponent().setFocusable(true);
Then in the actual class which extend UIOverlay I go
textFieldInput.addKeyListener(new KeyListener(){
public void keyPressed(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e) {
//this notices when 'enter' is pressed and the string in the text field should be sent to the
//text area for everyone to see when chatting
if(e.getKeyChar() == 10){
inputText = textFieldInput.getText();
System.out.println(inputText);
textFieldInput.setText(""); //clears the textfield after pressing enter
//textAreaScreen.append("\n" + inputText); //places the input text into the textArea
setMessage("\n" + inputText);
//client.processMessage(inputText);
}
}
});
I have a feeling I must be setting the listeners improperly. Are you able to tell just from those code snippets where I’m going wrong? Perhaps I’m setting one too many listeners or I’m setting up the main program listener improperly? Thank you very much for all your help.
--------------- EDIT ---------------
Okay, I looked through the UI source and I here’s what I think is going on. All events get caught by UIEventAdapter. UIEventAdapter then passes the event along to the overlay which has focus.
I got rid of the Toolkit.getDefaultToolkit code but now I’m not sure how I should set listeners for the main program window so that it receives events from the UIEventAdapter. Thanks again.
~shochu