Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Event/Focus/Key Listener Problem.

Posted on 1998-06-01
5
Medium Priority
?
311 Views
Last Modified: 2010-04-16
I am trying to write a java GUI application where one of the screen is to have several buttons.  I want to make it where I can simply type in (using the keyboard) a specified key and have the focus transfer from one key to the specified key.  For example, if key "A" has the focus and I want key "C" to gain the focus from key "A", I just want to press key C on the keyboard and not use the mouse.  This application is written for a power user I guess.
I can make the focus traverse the button list so that's not what I want, I want the focus to pass button B if its presently on button A and I type C on the keyboard.
0
Comment
Question by:visa
  • 2
  • 2
5 Comments
 

Author Comment

by:visa
ID: 1221849
Edited text of question
0
 
LVL 4

Expert Comment

by:evijay
ID: 1221850
Write a focus manager class which maintains a list of buttons (vector) whose focus need to be
managed. This focus manager class implements the KeyListener interface. It registers itself as a valid keylistener for all the buttons in the list. Also, register this focusmanager class as key listener to the  parent of all the buttons When a key event occurs on a button, the focus manager class callback gets called. In this keyPress method, send the focus to appropriate component using requestFocus method of that component (button).
0
 
LVL 1

Accepted Solution

by:
niges earned 60 total points
ID: 1221851
evijay: as that is a correct answer, why didn't you post it as an answer...

--nige

0
 
LVL 1

Expert Comment

by:niges
ID: 1221852
D'oh please reject that answer, I meant it as a comment not answer.

--Nige
0
 

Author Comment

by:visa
ID: 1221853
I understand the solution for the most part, but I do not understand fully the part about the "parent" of the buttons.  I don't exactly understand what this "parent" is.  Please clarify this to me.  Thanks.

Visa
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question