title: How to program the same button to do two tasks?
body: <p>I have a button called three_button and three_button.setText("Open");</p>
  
  <p>When user clicks button, a frame is opened by the setVisible(true) command.  And the button text changes to Close. Now when I click that button again, I want the frame to be closed this time because the frame is already visible. Code below. I tried creating another handler class within the same handler class, but it didn't work but. Any suggestions?</p>
  
  <p>In other words:</p>
  
  <pre><code>if(frame is visible and open) { the button once pressed should close the frame} 
  
  else if (frame is not opened) {the button once pressed should open the frame} 
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>thehandler handler = new thehandler();
  three_button.addActionListener(handler);
  
  private class thehandler implements ActionListener{ public void
  actionPerformed(ActionEvent event){
  
  TabbedPaneExample frame = new TabbedPaneExample();
  frame.setVisible(true);
  
  three_button.setText("Close"); }}
  </code></pre>