aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Facing problem with KeyListener for a frame having multiple panels Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Facing problem with KeyListener for a frame having multiple panels" Watch "Facing problem with KeyListener for a frame having multiple panels" New topic
Author

Facing problem with KeyListener for a frame having multiple panels

Seetamraj Sriharsha
Greenhorn

Joined: Nov 09, 2009
Posts: 20
I'm building the Shuffle game of 4X4 grid. I think you know about it I have completed it using single panel of 16 buttons. But now I'm facing problem when I thought of extending the application by adding two buttons in a separate panel.

Now the KeyListener is not at all working. I searched the forum and got some help from the following link. I followed the code of the forum member "Craig Wood" over there, but it didn't help me regarding the two buttons formed out of array in the second panel.

KeyListener Topic from this forum

Requirement is that the button has to slide to the empty slot when arrow keys are pressed. There are two buttons in other panel which, start a new game and refresh the present game.

Please help me out in adding KeyListeners thorough KeyBinding. (I will add action listeners to the 4X4 grid buttons in future so that user can slide them by clicking....I think this part is easy)

And please state on which component I should apply/add KeyBinding. Should add it to all the four buttons?

I will produce my work on KeyBinding if required. I just did it without any idea.



Main.java


MyFrame.java


OptionPanel.java


WorkPanel.java

pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
The answer was in the other thread that you linked to: don't use key listeners, use key binding.
Seetamraj Sriharsha
Greenhorn

Joined: Nov 09, 2009
Posts: 20
pete stein wrote:The answer was in the other thread that you linked to: don't use key listeners, use key binding.


That is what I wanted. I understood that I shouldn't use KeyListeners, but I don't understand how to use KeyBinding.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

Recommended reading
http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Facing problem with KeyListener for a frame having multiple panels