-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInfoGUI.java
More file actions
128 lines (122 loc) · 3.84 KB
/
Copy pathUserInfoGUI.java
File metadata and controls
128 lines (122 loc) · 3.84 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class UserInfoGUI extends JFrame implements ActionListener{
JTextField namefield,classfield;
JCheckBox musicCheck,sportCheck,travelCheck,boldCheck,italicCheck,underlineCheck;
JRadioButton fyButton,syButton,tyButton;
JComboBox<String> fontComboBox, sizeComboBox;
JTextArea resultArea;
JButton applybutton;
ButtonGroup classGroup;
public UserInfoGUI(){
setTitle("Student Information form");
setSize(400,600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(7,2,10,10));
setVisible(true);
JLabel namelabel= new JLabel("Your Name : ");
namefield = new JTextField(20);
add(namelabel);
add(namefield);
//Hobbies
JLabel hobbieslabel = new JLabel("Your Hobbies");
JPanel hobbiespanel = new JPanel();
musicCheck = new JCheckBox("Music");
sportCheck = new JCheckBox("Sport");
travelCheck = new JCheckBox("Travelling");
hobbiespanel.add(musicCheck);
hobbiespanel.add(sportCheck);
hobbiespanel.add(travelCheck);
add(hobbieslabel);
add(hobbiespanel);
//Font
JLabel fontlabel = new JLabel("Font Sytle :");
JPanel fontpanel = new JPanel();
boldCheck = new JCheckBox("Bold");
italicCheck = new JCheckBox("Italic");
underlineCheck = new JCheckBox("Underline");
fontpanel.add(boldCheck);
fontpanel.add(italicCheck);
fontpanel.add(underlineCheck);
add(fontlabel);
add(fontpanel);
//class
JLabel classlabel = new JLabel("Your Class : ");
JPanel classpanel = new JPanel();
fyButton = new JRadioButton("FY");
syButton = new JRadioButton("SY");
tyButton = new JRadioButton("TY");
classGroup = new ButtonGroup();
classGroup.add(fyButton);
classGroup.add(syButton);
classGroup.add(tyButton);
classpanel.add(fyButton);
classpanel.add(syButton);
classpanel.add(tyButton);
add(classlabel);
add(classpanel);
//font Options
JLabel fonttypelabel = new JLabel("Font type :");
fontComboBox = new JComboBox<>(new String[] {"Arial","Serif","Sansserif","Times new Roman"});
add(fonttypelabel);
add(fontComboBox);
//font size option
JLabel sizelabel = new JLabel("Font size :");
sizeComboBox = new JComboBox<>(new String[] {"8","10","12","14","16","18","20","25","60"});
add(sizelabel);
add(sizeComboBox);
//result area
resultArea = new JTextArea(5,40);
resultArea.setEditable(false);
JScrollPane scrollpane = new JScrollPane(resultArea);
add(new JLabel("Display All content : "));
add(scrollpane);
applybutton = new JButton("apply change");
applybutton.addActionListener(this);
add(applybutton);
}
public void actionPerformed(ActionEvent e){
String name = namefield.getText();
//get class
String className="";
if(fyButton.isSelected()){
className="FY";
}else if(syButton.isSelected()){
className ="SY";
}else if(tyButton.isSelected()){
className="TY";
}
//get hobbies
StringBuilder hobbies=new StringBuilder();
if(musicCheck.isSelected()){
hobbies.append("Music ");
}
if(sportCheck.isSelected()){
hobbies.append("Sport ");
}
if(travelCheck.isSelected()){
hobbies.append("travelling ");
}
//get font style
StringBuilder style= new StringBuilder();
if(boldCheck.isSelected()){
style.append("BOld ");
}
if(italicCheck.isSelected()){
style.append("Italic ");
}
if(underlineCheck.isSelected()){
style.append("Underline ");
}
//font type and size
String fontype= (String) fontComboBox.getSelectedItem();
String fontsize= (String) sizeComboBox.getSelectedItem();
//display result
resultArea.setText("Name : "+name+"\nClass : "+className+ "\nHobbies : "+hobbies.toString() +
"\nFont : "+ fontype +" "+fontsize+ "\n"+ style.toString());
}
public static void main(String[] args){
new UserInfoGUI();
}
}