Computer Science
Example with an applet that opens a second window.

import java.awt.event.*;
import java.awt.*;
import java.applet.Applet;

/* This applet only shows one button.  When that button is clicked, a second window opens. */
public class AppletFrame extends Applet
{
     private Panel panel;
     private Button showSecond;
     private SecondWindow second;
 
     public void init ()
     {
          panel = new Panel ();
          setBackground (Color.cyan);
          showSecond = new Button ("Show Frame");
          showSecond.addActionListener (new ShowSecondListener ());
          panel.add (showSecond);
          add (panel);
          second = new SecondWindow ();
     } // method init
 
     // When the showSecond button is clicked, the second window is shown.
     class ShowSecondListener implements ActionListener
     {
          public void actionPerformed (ActionEvent e) {second.show ();}
     } // class ShowSecondListener
} // class AppletFrame

/* This class creates a window frame that displays one button.  When the button is clicked the window is hidden. */
class SecondWindow extends Frame
{
     private Panel panel;
     private Button hideFrame;
 
     SecondWindow ()
     {
          super ("Second Frame");
          setSize (100, 300);
          panel = new Panel ();
          hideFrame = new Button ("Hide");
          hideFrame.addActionListener (new HideListener ());
          panel.add (hideFrame);
          add (panel);
     } // constructor
 
     // When the hideFrame button is clicked, the window is removed from the screen.
     class HideListener implements ActionListener
     {
         public void actionPerformed (ActionEvent e) {hide ();}
     } // class HideListener
} // class SecondWindow