/home/sjenks/NetBeansProjects/CS2/src/gui/GUI4.java |
1
2
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
17
18 public class GUI4 {
19
20
21 @param args
22
23 public static void main(String[] args) {
24 SwingUtilities.invokeLater(new ThreadForGUI());
25 }
26
27 private static class ThreadForGUI implements Runnable {
28
29 public ThreadForGUI() {
30 }
31
32 @Override
33 public void run() {
34 GUI4 gui = new GUI4();
35 }
36 }
37
38 public GUI4() {
39 KFrame frame = new KFrame("GUI 4");
40 }
41
42
43
44 private class KFrame extends JFrame{
45
46 private JButton blueButton;
47 private JButton redButton;
48 private JButton greenButton;
49 private JButton yellowButton;
50 private JLabel colorLabel;
51
52 public KFrame (String title){
53 super(title);
54 setSize(500,300);
55 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
56 addComponents(getContentPane());
57 setVisible (true);
58 }
59
60 private void addComponents (Container contentPane){
61 blueButton = new JButton ("Blue");
62 redButton = new JButton ("Red");
63 greenButton = new JButton ("Green");
64 yellowButton = new JButton ("Yellow");
65 colorLabel = new JLabel ("Press a button ...", SwingConstants.CENTER);
66 contentPane.setLayout(new BorderLayout());
67 contentPane.add(blueButton, BorderLayout.NORTH);
68 contentPane.add(redButton,BorderLayout.SOUTH);
69 contentPane.add(greenButton,BorderLayout.EAST);
70 contentPane.add(yellowButton,BorderLayout.WEST);
71 contentPane.add(colorLabel,BorderLayout.CENTER);
72 }
73 }
74 }