我可以让匿名事件处理程序方法像这样有条件地运行吗?
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);
}
}
});我如何才能使其成为有条件的?
发布于 2017-03-14 23:12:59
你当然可以,但是代码是无效的:
if (activeDataPanel.setVisible(false))也许你想检查你的面板是否可见,试着这样做:
if (activeDataPanel.isVisible())或者可能是activeDataPanel.getVisible(),我现在还不确定它的getter名称:)
https://stackoverflow.com/questions/42789668
复制相似问题