Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Facing problem with KeyListener for a frame having multiple panels

 
Seetamraj Sriharsha
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer was in the other thread that you linked to: don't use key listeners, use key binding.
 
Seetamraj Sriharsha
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic