1

Can I make anonymous event handler method to act conditional like

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

how can i make this conditional?

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
Ashford Tulgaa
  • 27
  • 2
  • 13

1 Answers1

1

Sure you can, but that code is not valid:

if (activeDataPanel.setVisible(false))

maybe you want to check if your panel is visible try it this way:

if (activeDataPanel.isVisible())

or maybe activeDataPanel.getVisible() I'm not sure about the getter name for it right now :)

xander
  • 1,780
  • 9
  • 16