So I've created a new class and called it gamePanel. It extends JPanel. I've added this panel to a frame, along with some buttons, in my main method. Essentially, by pressing buttons, it takes the focus off the panel which doesn't allow my key listeners (which were added to the panel) to work. Because gamePanel is a custom panel, and not a normal JPanel, using the method .requestFocusInWindow() doesn't work. so I made a method for my gamePanel object that when called upon will invoke the other method to give the focus back to the panel. However, it gives an error at the point in which my gamePanel object calls the method. So my ultimate question is, how can I get this working, or how can i return focus to my object?
If you need it, heres my code. Its long, and
you should only need to look at lines 143 in "test" and line 21 in "gamePanel".
gamePanel class: