Java 条件事件处理程序

Java 条件事件处理程序,java,events,jpanel,actionevent,Java,Events,Jpanel,Actionevent,我可以让匿名事件处理程序方法像条件一样工作吗 JButton activeDataBtn = new JButton("Active"); activeDataBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { if (activeDataPanel.setVisible(false)) { //Erroneous code

我可以让匿名事件处理程序方法像条件一样工作吗

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);   
     }
  }
 });

如何使此有条件?

当然可以,但该代码无效:

if (activeDataPanel.setVisible(false))
也许您想检查面板是否可见,请尝试以下方法:

if (activeDataPanel.isVisible())

或者可能
activeDataPanel.getVisible()
我现在不确定它的getter名称:)

有什么建议吗