First of all, thanks for taking the time to read my question, I appreciate that.
Here is an overview of what I have now:
I am writing a 3 by 3 slider puzzle using buttons in the form of grid cells. I added a JPanel key listener that contains these buttons and they respond perfectly to keyboard events.
However, the problem is somewhat peculiar, and I could not determine exactly why it exerts such unstable behavior. After clicking on one of these buttons, none of which are registered by event listeners, none of the buttons moves, but when you follow it with a key event, the keys stop responding.
My question is this: I know this is pretty vague, but does it call someone to be a Java problem, or does it sound like my error code behind all this?
I am really open to any suggestions, as it has been bothering me for about a week, and I still donβt know what caused the problem.
Again, thanks for taking the time to learn this.
@trashgod: yes of course.
public class Test2 extends JPanel{ JButton a = new JButton("A"); Test2(){ setFocusable(true);
}
Code Snippet Function: JPanel receives a key event, the left arrow to be exact, removes the "a" button and adds a new "b" button, and then the "a" button each time. However, if you try to run the program, after clicking the button, it simply stops listening to key events.
I was just thinking if this could have anything to do with the lost focus in JPanel? If so, what specific methods should I pay attention to restoring the lost focus?
Thanks!
(btw, setEnabled comments is my attempt to solve this problem by simply disabling the button, but it still does not explain how to restore lost focus on JPanel if this is a problem.)