Also available as WindowPlay.java

/**
 * A Simple stand-alone GUI program based on Swing.
 * Multiple windows.
 * 
 * This example uses a class that extends JFrame
 * instead of creating a JFrame object!
 * The main creates 2 of these objects,
 * and puts some buttons in one and a textfield
 * in another.
 *
 * @author Dave Hollinger
 * @version 1.0
 */

import javax.swing.*;
import java.awt.*;       // needed for Container


class WindowPlay extends JFrame {

  WindowPlay() {
        super();
        // establish what happens when the window is closed
        // (without this the program would keep running!)
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

  public static void main(String [] args) {
        WindowPlay w1 = new WindowPlay();
        WindowPlay w2 = new WindowPlay();

        w1.buttons();
        w2.textfield();

        w1.setSize(200,200);
        w1.setTitle("Button Window");
        w1.setVisible(true);

        w2.setSize(200,200);
        w2.setTitle("TextField Window");
        w2.setVisible(true);
  }


  // add buttons to content pane
  void buttons() {
        Container c = getContentPane();
        // establish the layout manager
        // 3 rows, 2 cols everything 5 pixels apart
        c.setLayout( new GridLayout(2,3,5,5));

        // add a bunch of buttons
        for (int i=0;i<6;i++) {
          JButton j = new JButton(new Integer(i).toString());
          // change the font
          j.setFont(new Font("Courier",Font.BOLD,20));
          // change the colors
          j.setBackground(Color.WHITE);
          j.setForeground(Color.BLACK);
          c.add(j);
        }
  }

  // add a single textfield to content pane
  void textfield() {
        Container c = getContentPane();

        c.setLayout(new FlowLayout());
        c.setBackground(Color.BLUE);

        // add single text field
        JTextField t = new JTextField();
        t.setText("Hello World");
        t.setSize(100,40);
        t.setFont(new Font("TimesRoman",Font.BOLD,30));
        t.setBackground(Color.WHITE);
        t.setForeground(Color.BLACK);
        c.add(t);
  }
                          

}