I am a beginner to Java programming and I am trying to create a menu for a simple Snake game which will contain three buttons(New Game, Difficulty, Quit). I created a class for the menu and a class for the mouse input. I also used an enum to store the states of the game (MAIN_MENU, DIFFICULTY_MENU and GAME) and a variable called state which stores the current state.
The main issue is that although the state of the game changes when I press the New Game button, the game itself doesn't start. I have tried countless ways to make it work ranging from adding game state checks inside the methods that are involed in rendering the gameplay to actually calling those methods when the button is pressed but none of them worked. I also tried adding JButtons to create the menu and I managed to make them dissappear when the New Game was pressed but the game wouldn't start either. Any help would be greatly appreciated. Here's some of the code(if it's too much please let me know and i will post only specific parts of it):
So, is there anybody who could help me figure out how to start the game when the button is pressed? So far I have only been able to make the "Quit" button work.
I run the code a couple more times and I discovered that if I minimize the window after pressing "New Game" and then reopen it the game refreshes and can be played afterwards. Any ideas on why it works this way and how I can "refresh" the JFrame immediately after pressing the menu button?