如何让程序等待 GUI 其他部分的点击?

huangapple 未分类评论53阅读模式
英文:

How do I get the program to wait for a click on another part of the GUI?

问题

我正在编写一个游戏。在玩家的回合中,他们需要从动作列表中选择一个动作。为此,我使用了添加到pnlActionButtons(JPanel)的MouseAdapter,上面绘制了动作的图标。也就是说,他们会点击“要做的事情”的图片,然后将其转换为变量,我会在mouseReleased()方法内部进行切换。

我遇到的难题是,在某些游戏动作中,我需要选择2个物品以提供动作的上下文。例如,我需要点击游戏棋子和目标位置。我该如何让pnlActionButtons中的mouseReleased()等待在Gameboard(扩展JPanel)中进行点击,以将上下文传递到我需要的位置?

英文:

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?

huangapple
  • 本文由 发表于 2020年4月11日 08:24:55
  • 转载请务必保留本文链接:https://java.coder-hub.com/61150594.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定