I am designing a classic snake game where the user selects a level of difficulty (through JRadioButtons) and controls the snake using the arrow keys. I have 2 JPanels: SetupPanel and SnakePanel that are added to a JFrame, GameFrame. I am using a thread to make the snake move.

Right now I am trying to add functionality to the JRadioButtons, making the speed faster as the difficulty increases. The snake operates fine until I select a new difficulty (on the SetupPanel). Then the snake continues movement in the SnakePanel, but you can no longer move the snake with the arrow keys.

I am pretty sure that this is a focus issue, and have spent hours reading the tutorials but nothing seems to help.

```
public class GameFrame extends JFrame{

    this.add(new SetupPanel(), BorderLayout.NORTH);

    SnakePanel snakePanel = new SnakePanel();
    this.add(snakePanel, BorderLayout.SOUTH);

    setLocationRelativeTo(null);

    setVisible(true);
    snakePanel.requestFocusInWindow();  //without this my thread doesn't work
}

public class SetupPanel extends JPanel{

    JLabel statusLbl;

    public SetupPanel(){

        super();
        //add all of the JRadioButtons
        //add them to a button group

    }

private class LevelHandler implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {

        if(e.getSource() == begButton){
            speed = 100000;
        }

        if(e.getSource() == intButton){
            speed = 400000;
        }

        if(e.getSource() == advButton){
                speed = 700000;
            }

            setFocusable(false);   //Doesn't seem to make a difference

        }

    }

}

```

Then, what I am most confused about is my SnakePanel:

```
public class SnakePanel extends JPanel implements Runnable{
    public SnakePanel() {

        setFocusable(true); //Focus on this panel or snake won't move

        //I have also tried these lines to keep focus on this 
        //panel but it doesn't work either
        //this.addFocusListener(new FocusAdapter() {
        //   public void focusLost(FocusEvent ev) {
        //   requestFocus();
        //   }
        //  });

        //set what it will look like, size, etc...

        this.addKeyListener(new Key());
        startMoving();
    }

    private void startMoving(){
        running = true;
        thread = new Thread(this, "snake movement");
        thread.start();
    }

    @Override
    public void run() {
        while(running){
            move();       //things program does each time snake moves
            repaint();
        }
    }

    //KeyListeners

}

```