title: How to attach a window to another window
body: <p>Please have a look at the following code</p>
  
  <p><strong>Main.Java</strong></p>
  
  <pre><code>import java.awt.event.*;
  import java.awt.*;
  import javax.swing.*;
  
  
  public class Main extends JFrame
  {
      private JButton ok;
  
      public Main()
      {
          ok = new JButton("OK");
          ok.addActionListener(new ButtonAction());
  
          JPanel panel = new JPanel();
          panel.setLayout(new FlowLayout());
          panel.add(ok);
  
          getContentPane().add(panel,"South");
  
          this.setVisible(true);
          this.setSize(new Dimension(200,200));
          this.validate();
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      }
  
      public static void main(String[]args)
      {
          try
          {
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              new Main();
          }
          catch(Exception e)
          {
  
          }
      }
  
      private class ButtonAction implements ActionListener
      {
          public void actionPerformed(ActionEvent ae)
          {
              Dialog d = new Dialog();
              d.setVisible(true);
          }
      }
  
  }
  </code></pre>
  
  <p><strong>Dialog.java</strong></p>
  
  <pre><code>import java.awt.Event;
  import java.awt.*;
  import javax.swing.*;
  
  
  public class Dialog extends JDialog
  {
      private JButton done;
  
      public Dialog()
      {
          done = new JButton("Done");
  
          this.add(done);
  
          this.setSize(new Dimension(400,200));
      }
  
  }
  </code></pre>
  
  <p>In here, I want to "attach" the Dialog form to the main form. Which means, when I click the OK button in Main.Java, Dialog form will get attached to the right side of the main form. So, when I move the main form, the dialog also get moved. However, dialog form should be independent, which means, when I click "x" button in dialog form, only that form exists, not the main form.</p>
  
  <p>How can I attach this dialog form, to the right side of the main form, when the button is clicked? Please help!</p>