C:\Users\notebook\Documents\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 @Override
29 public void run() {
30 GUI3 gui = new GUI3();
31 }
32 }
33
34 public GUI3() {
35 KFrame frame = new KFrame("GUI 3");
36 }
37
38
39 private class KFrame extends JFrame {
40
41 private JButton blueButton;
42 private JButton redButton;
43 private JButton greenButton;
44 private JButton yellowButton;
45 private JLabel colorLabel;
46
47 public KFrame(String title) {
48 super(title);
49 setSize(500, 300);
50 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
51 addComponents(getContentPane());
52 setVisible(true);
53 }
54
55 private void addComponents(Container contentPane) {
56 blueButton = new JButton("Blue");
57 redButton = new JButton("Red");
58 greenButton = new JButton("Green");
59 yellowButton = new JButton("Yellow");
60 colorLabel = new JLabel("Press a button ...");
61 contentPane.setLayout(new FlowLayout());
62 contentPane.add(blueButton);
63 contentPane.add(redButton);
64 contentPane.add(greenButton);
65 contentPane.add(yellowButton);
66 contentPane.add(colorLabel);
67 }
68
69 }
70
71 }
72