-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleCB.java
More file actions
57 lines (52 loc) · 1.63 KB
/
Copy pathSimpleCB.java
File metadata and controls
57 lines (52 loc) · 1.63 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SimpleCB extends JFrame implements ActionListener
{
JCheckBox musicCheck, sportsCheck, travelCheck;
JTextField classField;
JButton applyButton;
public SimpleCB() {
// Set up the frame
setTitle("Check Box Form");
setSize(300, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(4, 3, 10, 10));
classField = new JTextField("");
// Your Hobbies
JLabel hobbiesLabel = new JLabel("Your Hobbies :");
JPanel hobbiesPanel = new JPanel();
musicCheck = new JCheckBox("Music");
sportsCheck = new JCheckBox("Sports");
travelCheck = new JCheckBox("Traveling");
hobbiesPanel.add(musicCheck);
hobbiesPanel.add(sportsCheck);
hobbiesPanel.add(travelCheck);
add(hobbiesLabel);
add(hobbiesPanel);
applyButton = new JButton("Apply Changes");
applyButton.addActionListener(this);
add(applyButton);
add(classField);
setVisible(true);
}//constructor
@Override
public void actionPerformed(ActionEvent e) {
// Get hobbies
StringBuilder hobbies = new StringBuilder();
if (musicCheck.isSelected()) {
hobbies.append("Music ");
}
if (sportsCheck.isSelected()) {
hobbies.append("Sports ");
}
if (travelCheck.isSelected()) {
hobbies.append("Traveling ");
}
classField.setText(hobbies.toString());
}
public static void main(String[] args)
{
new SimpleCB();
}
}