Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (754)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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 1599 times)
0 Members and 1 Guest are viewing this topic.
Offline shochu

Junior Devvie

Java games rock!

« Posted 2003-12-14 00: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 Devvie

Java games rock!

« Reply #1 - Posted 2003-12-14 00: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 ( 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

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

Junior Devvie

Java games rock!

« Reply #2 - Posted 2003-12-14 01: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 ...

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

For the overlay I do

            UIEventAdapter eventAdapter = new UIEventAdapter(windowMgr);

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();
                              textFieldInput.setText(""); //clears the textfield after pressing enter
                              //textAreaScreen.append("\n" + inputText); //places the input text into the textArea
                              setMessage("\n" + 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.
Pages: [1]
  ignore  |  Print  

DesertCoockie (22 views)
2018-05-13 18:23:11

nelsongames (74 views)
2018-04-24 18:15:36

nelsongames (68 views)
2018-04-24 18:14:32

ivj94 (751 views)
2018-03-24 14:47:39

ivj94 (81 views)
2018-03-24 14:46:31

ivj94 (605 views)
2018-03-24 14:43:53

Solater (97 views)
2018-03-17 05:04:08

nelsongames (178 views)
2018-03-05 17:56:34

Gornova (388 views)
2018-03-02 22:15:33

buddyBro (1048 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!