C:\Users\notebook\Documents\NetBeansProjects\CS2\src\gui\GUI4.java
 1 /*
 2  * GUI4 placces some dead buttons in the frame using a BorderLayout manager.
 3  */
 4 package gui;
 5 
 6 import java.awt.BorderLayout;
 7 import java.awt.Container;
 8 import javax.swing.JButton;
 9 import javax.swing.JFrame;
10 import javax.swing.JLabel;
11 import javax.swing.SwingConstants;
12 import javax.swing.SwingUtilities;
13 
14 /**
15  *
16  * @author notebook
17  */
18 public class GUI4 {
19 
20     /**
21      * @param args the command line arguments
22      */
23     public static void main(String[] args) {
24         SwingUtilities.invokeLater(new ThreadForGUI());
25     }
26 
27     private static class ThreadForGUI implements Runnable {
28 
29         @Override
30         public void run() {
31             GUI4 gui = new GUI4();
32         }
33     }
34 
35     public GUI4() {
36         KFrame frame = new KFrame("GUI 4");
37     }
38 
39     // modeling the featured frame of the GUI
40     private class KFrame extends JFrame {
41 
42         private JButton blueButton;
43         private JButton redButton;
44         private JButton greenButton;
45         private JButton yellowButton;
46         private JLabel colorLabel;
47 
48         public KFrame(String title) {
49             super(title);
50             setSize(500, 300);
51             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
52             addComponents(getContentPane());
53             setVisible(true);
54         }
55 
56         private void addComponents(Container contentPane) {
57             blueButton = new JButton("Blue");
58             redButton = new JButton("Red");
59             greenButton = new JButton("Green");
60             yellowButton = new JButton("Yellow");
61             colorLabel = new JLabel("Press a button ...",
62                     SwingConstants.CENTER);
63             contentPane.setLayout(new BorderLayout());
64             contentPane.add(blueButton, BorderLayout.NORTH);
65             contentPane.add(redButton, BorderLayout.SOUTH);
66             contentPane.add(greenButton, BorderLayout.EAST);
67             contentPane.add(yellowButton, BorderLayout.WEST);
68             contentPane.add(colorLabel, BorderLayout.CENTER);
69         }
70 
71     }
72 
73 }
74