0

I am programming a game. During a player's turn, they will need to select an action from a list of actions. For this purpose, I am using a MouseAdapter added to pnlActionButtons (JPanel) that has the action iconography painted on it. I.e. they would click on the picture of the "thing to do" and that gets translated into variable that I switch on inside of the mouseReleased() method.

Where I am running into a roadblock is that, for some game actions, I need to select 2 items to provide context for the action. E.g., I need the game piece clicked on and a destination to move it to. How do I get the mouseReleased() in pnlActionButtons to wait for clicks in Gameboard (extends JPanel) to pass the context to where I need it?

MDHackbert
  • 123
  • 1
  • 1
  • 6
  • You're stuck thinking in linear console programming mode when you should be thinking in event-driven programming mode where the program's response to mouse click or other input will depend on the program's *state* (whose turn it is, for instance). Re-think the whole thing. – Hovercraft Full Of Eels Apr 11 '20 at 00:54
  • In other words, your program *doesn't wait*, but instead changes how it responds to button clicks depending on the values held by key program variables, state variables. – Hovercraft Full Of Eels Apr 11 '20 at 00:54

0 Answers0