Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Keeping ActionEvents seperate for each Overlay  (Read 905 times)
0 Members and 1 Guest are viewing this topic.
Offline shochu

Junior Member




Java games rock!


« Posted 2003-12-14 01:08:39 »

What's the best way to handle events for multiple overlays?

Is it best to have one mouse listener and one keyboard listener for your entire program then check which overlay has the focus to see where the actions should go.

Or should each overlay have it's own listener and the listener only reacts if its respective overlay has focus.  

I was thinking it would be better for each overlay to have it's own listeners which start with an if statement checking for focus.  If the overlay has focus then it does the appropriate action and consumes the event.  

Has anyone had to deal with this before?

My overlays include things like chat windows so they do more then just display data. Thanks for the advice.

Also, I just wanted to thank everyone who has been so helpful lately.  My classes are starting to wind down so I have a lot of time recently to program using xith3d for my own education and enjoyment.  Hence, the large influx of questions to the boards.  
Offline DavidYazel

Junior Member




Java games rock!


« Reply #1 - Posted 2003-12-14 01:47:00 »

Currently if you click on a UIWindow it will get keyboard focus and all keyboard events will be sent to it.  Mouse events are sent to the UIWindow that the mouse is over.  We have a new chat system which you can read about here (http://www.magicosm.net/magicosm_user_manual.pdf) and forgive me since the manual is not complete yet.  We use the current Xith3D UI system to support our chat windows, so what you are asking to do is certainly possible with then current rev of Xith3D.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline shochu

Junior Member




Java games rock!


« Reply #2 - Posted 2003-12-14 02:02:49 »

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 ...

1  
                  Toolkit.getDefaultToolkit().addAWTEventListener(new KeyboardEventListener(keyEventList),AWTEvent.KEY_EVENT_MASK);
                             

For the overlay I do

1  
2  
3  
4  
5  
            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
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
            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
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (72 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (79 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (80 views)
2014-04-14 15:48:38

tom_mai78101 (104 views)
2014-04-10 04:04:31

BurntPizza (164 views)
2014-04-08 23:06:04

tom_mai78101 (260 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!