-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSwingCheckbox.java
More file actions
85 lines (65 loc) · 2.13 KB
/
SwingCheckbox.java
File metadata and controls
85 lines (65 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package src.uni.lessons.jswing;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;
public class SwingCheckbox extends JFrame implements ItemListener {
private JCheckBox checkbox1;
private JCheckBox checkBox2;
private JLabel label1;
private JLabel label2;
private JTextField textField1;
private JTextField textField2;
private JButton button1;
private JButton button2;
private JButton button3;
public SwingCheckbox(String title) {
super(title);
}
public void createWindow() {
checkbox1 = new JCheckBox("Snap to Grid");
checkBox2 = new JCheckBox("Show Grid");
checkbox1.addItemListener(this);
checkBox2.addItemListener(this);
label1 = new JLabel("X:");
label2 = new JLabel("Y:");
textField1 = new JTextField(3);
textField2 = new JTextField(3);
button1 = new JButton("Ok");
button2 = new JButton("Cancel");
button3 = new JButton("Help");
add(checkbox1);
add(checkBox2);
add(label1);
add(label2);
add(textField1);
add(textField2);
add(button1);
add(button2);
add(button3);
setLayout(null);
checkbox1.setBounds(50, 0, 300, 50);
checkBox2.setBounds(50, 20, 300, 50);
label1.setBounds(250, 0, 300, 50);
label2.setBounds(250, 20, 300, 50);
textField1.setBounds(270, 10, 100, 25);
textField2.setBounds(270, 35, 100, 25);
button1.setBounds(420, 0, 100, 30);
button2.setBounds(420, 35, 100, 30);
button3.setBounds(420, 65, 100, 30);
setSize(550, 150);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void itemStateChanged(ItemEvent i) {
System.out.println(checkbox1.isSelected());
System.out.println(checkBox2.isSelected());
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SwingCheckbox("Align").createWindow();
}
});
}
}