2017-03-14 123 views
1

我可以匿名事件處理方法行事條件像有條件的事件處理程序

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

我怎麼能做出這樣的條件?

+0

任何建議appriciated –

回答

1

當然可以,但這些代碼是無效的:

if (activeDataPanel.setVisible(false)) 

也許你要檢查,如果你的面板是可見試試這樣說:

if (activeDataPanel.isVisible()) 

也許activeDataPanel.getVisible()我不知道現在的吸氣劑名稱:)

+0

噢,非常感謝你,這解決了它:) –