Java中JCheckBox问题
classo1ListenerimplementsItemListener{@OverridepublicvoiditemStateChanged(ItemEvente)...
class o1Listener implements ItemListener{
@Override
public void itemStateChanged(ItemEvent e) {
if(operator1.isSelected()){
operator2.setSelected(false);
operator3.setSelected(false);
operator=1;
System.out.println(operator);
}
// TODO Auto-generated method stub
}
}
class o2Listener implements ItemListener{
@Override
public void itemStateChanged(ItemEvent e) {
if(operator2.isSelected()){
operator1.setSelected(false);
operator3.setSelected(false);
operator=2;
System.out.println(operator);
}
// TODO Auto-generated method stub
}
}
class o3Listener implements ItemListener{
@Override
public void itemStateChanged(ItemEvent e) {
if(operator3.isSelected()){
operator1.setSelected(false);
operator2.setSelected(false);
operator=3;
System.out.println(operator);
}
// TODO Auto-generated method stub
}
}
这是我三个JCheckBox----operator1,operator2,operator3的事件,把if(operator3.isSelected())去掉和加上意思会有什么不同嘛?为什么我去掉之后就乱了,求解释。 展开
@Override
public void itemStateChanged(ItemEvent e) {
if(operator1.isSelected()){
operator2.setSelected(false);
operator3.setSelected(false);
operator=1;
System.out.println(operator);
}
// TODO Auto-generated method stub
}
}
class o2Listener implements ItemListener{
@Override
public void itemStateChanged(ItemEvent e) {
if(operator2.isSelected()){
operator1.setSelected(false);
operator3.setSelected(false);
operator=2;
System.out.println(operator);
}
// TODO Auto-generated method stub
}
}
class o3Listener implements ItemListener{
@Override
public void itemStateChanged(ItemEvent e) {
if(operator3.isSelected()){
operator1.setSelected(false);
operator2.setSelected(false);
operator=3;
System.out.println(operator);
}
// TODO Auto-generated method stub
}
}
这是我三个JCheckBox----operator1,operator2,operator3的事件,把if(operator3.isSelected())去掉和加上意思会有什么不同嘛?为什么我去掉之后就乱了,求解释。 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询