0
public void actionPerformed(ActionEvent e) {
    if (text1.equals(e.isSelected())) {
        System.out.println("test");
    }
    else {
        System.out.println("error");
        }
    }
}

text1 是我的 JButton 出于某种原因,isSelected 不起作用,有人知道为什么吗?任何帮助表示赞赏!

提前致谢,

-卡梅隆

4

2 回答 2

1

这个问题提出了更多的问题。

就其性质而言,JButton不支持该属性isSelectedisSelected由切换样式按钮使用,JRadioButton例如JCheckBoxJToggleButton

根据您问题的性质,如果JButton单击,它将被“选中”

public void actionPerformed(ActionEvent e) {
    System.out.println("text1 has being selected");
}
于 2013-06-17T00:08:15.807 回答
1

isSelected是未定义的ActionEvent。如果ActionListener是唯一注册到 的JButton,那么代码将很简单:

text1.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent event) {

       System.out.println("test");
    }
});
于 2013-06-16T23:46:50.267 回答