你能详细告诉我我怎么知道一个jcheckbox是否被选中?方法 isSelected 对我不起作用它在运行时给了我一个异常
{
Sandwich = new JButton("Tall");
contentPane.add(Tall);
Sandwitch.setBounds(350, 110, 90,40); //in main
Sandwitch.addActionListener(this);
}
.....
public void actionPerformed(ActionEvent event) {
JButton clickedButton = (JButton) event.getSource();
String buttonText = clickedButton.getText();
..........
if(clickedButton.getText()=="Sandwitch"){
if(Ketchup.getState()&&!Garlic.getState()){//
itm=new Item(""+m+clickedButton.getText(),3.0);
xyz.addItem(itm);
textArea.append(" "+clickedButton.getText()+",");
textArea.append(" "+itm.getPrice()+"\n");}
else if(!Ketchup.isSelected()&&Garlic.isSelected()){//
....................
}
它在运行时给出了一个很长的异常
你能帮我解决这个问题吗?