java条件事件处理程序
我可以让匿名事件处理程序方法像条件一样工作吗
JButton activeDataBtn = new JButton("Active");
activeDataBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
if (activeDataPanel.setVisible(false)) { //Erroneous code
readDataFromFile(); //a method reads data from .csv
//file and shows it on activeDataPanel
activeDataPanel.setVisible(true);
}
else
activeDataPanel.setVisible(false);
}
}
});
我怎样才能使这个有条件
# 1 楼答案
当然可以,但该代码无效:
也许您想检查面板是否可见,请尝试以下方法:
或者
activeDataPanel.getVisible()
我现在不确定它的getter名称:)