Source of TestGUISwing4.java


  1: //TestGUISwing4.java
  2: //Add two buttons to a panel and add a panel to the frame.
  3: //Then add another button to the frame.

  5: import java.awt.*;
  6: import java.awt.event.*;
  7: import javax.swing.*;

  9: public class TestGUISwing4
 10: {
 11:     public static void main(String[] args)
 12:     {
 13:         JFrame frame = new JFrame("My JFrame");
 14:         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 16:         JPanel panel = new JPanel();
 17:         JButton b1 = new JButton("First");
 18:         JButton b2 = new JButton("Second");
 19:         panel.add(b1);
 20:         panel.add(b2);
 21:         frame.getContentPane().add(panel);
 22:         
 23:         JButton b3 = new JButton("Third");
 24:         frame.getContentPane().add(b3);

 26:         frame.pack();
 27:         frame.show();
 28:     }
 29: }