Source of TestGUISwing5.java


  1: //TestGUISwing5.java
  2: //First, set the layout of the frame to FlowLayout.
  3: //Then add two buttons to a panel and add a panel to the frame.
  4: //Then add another button to the frame.

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

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

 17:         frame.getContentPane().setLayout(new FlowLayout());

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

 29:         frame.pack();
 30:         frame.show();
 31:     }
 32: }