Source of TestGUISwing9.java


  1: //TestGUISwing9.java
  2: //Show 

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

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

 15:         JPanel panel = new JPanel();
 16:         panel.setBackground(Color.YELLOW);
 17:         JButton b1 = new JButton("First");
 18:         JButton b2 = new JButton("Second");
 19:         panel.add(b1);
 20:         panel.add(b2);
 21:         panel.setBorder(BorderFactory.createEmptyBorder(30, //top
 22:                                                         30, //left
 23:                                                         10, //bottom
 24:                                                         30) //right
 25:                        );
 26:  
 27:         
 28:         JButton b3 = new JButton("Third");
 29:         b3.setBackground(Color.WHITE);

 31:         JLabel label = new JLabel("Center", SwingConstants.CENTER);
 32:         label.setOpaque(true);
 33:         label.setBackground(Color.CYAN);

 35:         frame.getContentPane().add(panel, BorderLayout.NORTH);
 36:         frame.getContentPane().add(b3, BorderLayout.SOUTH);
 37:         frame.getContentPane().add(label, BorderLayout.CENTER);

 39:         frame.pack();
 40:         frame.show();
 41:     }
 42: }