0

I have a combobox where I need the user to select something before the program can continue further. Is there someway to make sure the user has selected something before proceeding?

4

4 回答 4

3

我建议禁用所有相关组件,直到用户选择它的值。选择更改后,您可以重新启用这些组件。

于 2013-04-24T00:13:30.817 回答
2

Check the JComboBox API and you'll find methods that will help you such as getSelectedItem() and getSelectedIndex(). Actually if you checked the API, you wouldn't have even needed to ask this question here. It's a great resource that you will want to get into the habit of using.

于 2013-04-24T00:04:54.787 回答
1

您可以将代码的那部分移动到您“继续”的位置,直到用户对组合框执行操作。请参阅动作侦听器

于 2013-04-24T00:09:45.423 回答
0

Java中有一个用于此的接口。您可以在此处了解如何创建:ActionListener。这个接口处理我引用“一个动作事件发生,只要用户执行一个动作”。因此,在您的情况下,当用户在游戏继续之前单击某些内容时,您可以添加以下内容:

continueGame();

在 actionPerformed 方法下,并在该方法下有更多代码来处理你想要的。

我希望这对其他人有所帮助,因为我对这个问题迟了 2 年。

于 2015-10-26T06:14:27.563 回答