Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (775)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
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  
  swing vs keylistener  (Read 2422 times)
0 Members and 1 Guest are viewing this topic.
Offline Kova

Senior Devvie





« Posted 2006-08-06 18:10:15 »

Hello.
So I have a game menu and to get out fast from game I put keylistener and if ESC is pressed game shuts down. Problem is for creating game, joining and such I've put swing components and when you are entering data or you finished entering data focus stays on swing components so my keylistener can't register when ESC is pressed (swing keylistener is in charge then). Is there a quick and painless solution for this? When typing game name and such nobody uses ESC... can I make my keylistener work in parallel with swing's?
Offline CommanderKeith
« Reply #1 - Posted 2006-08-07 07:40:12 »

Hi,

You can do that by adding ESC to the list of keys listened to by the swing components by default - like 'TAB' (change focus) and 'SPACE' (activate), which always work for any swing component.  Sorry I can't remember how to do it exactly, just look up the API docs to find out how these keys are always listened to.


Offline cylab

JGO Kernel


Medals: 188



« Reply #2 - Posted 2006-08-07 07:59:29 »

You could add an EventListener directly to the AWTEvent queue.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
  Toolkit.getDefaultToolkit().addAWTEventListener(
     new AWTEventListenereventListener()
     {
        public void eventDispatched(AWTEvent event)
        {
           // Implement your key listenening here
        }
     },
     0xffffffff   // This gets all events. You should mask out the ones you don't need
   );

See the API documentation for details.

Mathias - I Know What [you] Did Last Summer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline fletchergames

Senior Devvie





« Reply #3 - Posted 2006-08-07 17:48:29 »

In my games, I add the keylistener to every child component of the component I want to listen to, as well as to the component itself.
Offline Kova

Senior Devvie





« Reply #4 - Posted 2006-08-08 02:03:19 »

tnx guys, I think I'll try Keith's advice first as it seems most OOP... but tnx for all other solutions, always nice to know other ways to do stuff.
Writing awt listener seems to deep, rough, not java like, also as adding listeners to many components.
Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (45 views)
2018-11-16 13:46:03

hadezbladez (50 views)
2018-11-16 13:41:33

hadezbladez (29 views)
2018-11-16 13:35:35

hadezbladez (20 views)
2018-11-16 13:32:03

EgonOlsen (1900 views)
2018-06-10 19:43:48

EgonOlsen (1936 views)
2018-06-10 19:43:44

EgonOlsen (1286 views)
2018-06-10 19:43:20

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

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

nelsongames (2043 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!