Q:

JAVA formWindowClosed

  this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
        this.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent e)
      {
          new AddPatient().setVisible(false);
          new SearchPatient().setVisible(true);
      }
    });

Got a problem regards with code above. Is this the right way to trigger the dispose and at the same time setVisible of anothe JFrame?
Could someone tell me is that the right way to code it?

A:

Sure. 
frame.addWindowListener(new WindowAdapter()
{
  public void windowClosing(WindowEvent e)
  {
      //open other frame
  }
});

