錯誤在線「grill =(String) grilled.isSelected();」和烤是先前宣佈的JCheckBox:烤?,我不斷調用isSelected();不能調用isSelected();原始類型布爾值「無法調用isSelected();在原始類型上布爾型
我只想要烤複選框,以便在我的小應用程序,將返回字符串
public void displayData()
{
System.out.println(" At Method Display Data");
String ssize, sandwich, drink, side, grill;
ssize = (String) size.getSelectedItem();
boolean grilled = true;
String str = String.valueOf(grilled);
System.out.println("String is: "+str);
grill = (String) grilled.isSelected();
sandwich = (String) Sandwiches.getSelectedValue();
side = (String) Drinks.getSelectedValue();
drink = (String) Sides.getSelectedValue();
JTextField textDisplay = new JTextField (ssize+ grill
+ sandwich + side + "with" + drink);
}
所以'烤'等於'真'。什麼是'grilled.isSelected()'應該做的? – khelwood
我從不使用isSelected()方法。我建議你使用一個布爾實例變量:'boolean checked = false',然後使用onClick來改變它:看到這個https://stackoverflow.com/questions/41446484/radiobutton-returns-false-after-first-run/41447094 #41447094 – Curio
我讀過,它應該返回,如果複選框被選中或不是,這是我的第一個交互式小程序,並且我希望字符串「烤」顯示在JFrame上,當用戶檢查它時和之後放置他們的訂單 - 這是一個更大的三明治店小應用程序的一部分,我正在爲上課和它的350行長,我不想在這裏發佈整個事情。 – Sarah