我正在为拼贴做一个项目(比如餐厅),而且我的 Java 不是很好(他们并没有真正尝试教我们)。该项目的原理是显示一条消息,说明我选择了哪些单选按钮和复选框。
我有 5 个单选按钮,它们用于选择一餐,以及 5 个用于选择配菜的复选框。我已经设法让单选按钮工作,但我不知道如何使复选框工作......
这是单选按钮的代码(这适用于所有 5 个):
private void jRadioButton1ItemStateChanged(java.awt.event.ItemEvent evt) {
if (evt.getSource().equals(jRadioButton1))
{
Meal= jRadioButton1.getText(); //Meal is a String
}
我为复选框尝试了相同的代码,但它只在消息中显示一个配菜,即使我选择了多个......
显示消息的按钮代码:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(rootPane, "You have chosen:\n" + String.valueOf(Meal) + "\n" + String.valueOf(SideDish));
}
So basically, if anyone is willing to help, please tell me how to make the check boxes work... that every selected check box is shown in the message, like this:
You have chosen:
Pizza //meal
Ketchup //selected side dish #1
Chilli peppers //selected side dish #2
Feta cheese //selected side dish #3
我希望我的问题很清楚...