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