-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIITDUFootballLeague.java
More file actions
218 lines (199 loc) · 9.64 KB
/
Copy pathIITDUFootballLeague.java
File metadata and controls
218 lines (199 loc) · 9.64 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import javax.swing.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class IITDUFootballLeague {
public static void main(String[] args) {
JFrame frame = new JFrame("IIT DU Football League Registration Form");
frame.setSize(420, 600);
frame.setLayout(null);
JLabel usernameLabel = new JLabel("Player name:");
usernameLabel.setBounds(10,10,100,20);
frame.add(usernameLabel);
JTextField usernameField = new JTextField();
usernameField.setBounds(100,10,200,20);
frame.add(usernameField);
JLabel emailLabel = new JLabel("Email:");
emailLabel.setBounds(10,40,100,20);
frame.add(emailLabel);
JTextField emailField = new JTextField();
emailField.setBounds(100,40,200,20);
frame.add(emailField);
JLabel phoneLabel = new JLabel("Phone:");
phoneLabel.setBounds(10,70,100,20);
frame.add(phoneLabel);
JTextField phoneField = new JTextField();
phoneField.setBounds(100,70,200,20);
frame.add(phoneField);
JLabel addressLabel = new JLabel("Address:");
addressLabel.setBounds(10,100,100,20);
frame.add(addressLabel);
JTextField addressField = new JTextField();
addressField.setBounds(100,100,200,20);
frame.add(addressField);
JLabel genderLabel = new JLabel("Gender:");
genderLabel.setBounds(10,130,100,20);
frame.add(genderLabel);
JRadioButton male = new JRadioButton("Male");
male.setBounds(100,130,70,20);
frame.add(male);
JRadioButton female = new JRadioButton("Female");
female.setBounds(170,130,70,20);
frame.add(female);
ButtonGroup genderGroup = new ButtonGroup();
genderGroup.add(male);
genderGroup.add(female);
JLabel DOBLabel = new JLabel("Date of Birth:");
DOBLabel.setBounds(10,160,100,20);
frame.add(DOBLabel);
String[] days = new String[31];
for (int i = 1; i <= 31; i++) {
days[i-1] = String.valueOf(i);
}
String[] months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
String[] years = new String[100];
for (int i = 0; i < 100; i++) {
years[i] = String.valueOf(2025-i);
}
JComboBox<String> dayComboBox = new JComboBox<>(days);
dayComboBox.setBounds(100,160,50,20);
JComboBox<String > monthComboBox = new JComboBox<>(months);
monthComboBox.setBounds(150,160,50,20);
JComboBox<String> yearComboBox = new JComboBox<>(years);
yearComboBox.setBounds(200,160,60,20);
frame.add(dayComboBox);
frame.add(monthComboBox);
frame.add(yearComboBox);
JLabel degreeLabel = new JLabel("Degree:");
degreeLabel.setBounds(10,190,100,20);
frame.add(degreeLabel);
JRadioButton bsse = new JRadioButton("BSSE");
bsse.setBounds(100,190,70,20);
frame.add(bsse);
JRadioButton msse = new JRadioButton("MSSE");
msse.setBounds(170,190,70,20);
frame.add(msse);
ButtonGroup degreeGroup = new ButtonGroup();
degreeGroup.add(bsse);
degreeGroup.add(msse);
JLabel batchLabel = new JLabel("Batch:");
batchLabel.setBounds(10,220,100,20);
frame.add(batchLabel);
String[] batches = new String[17];
for (int i = 0; i < 17; i++) {
batches[i] = String.valueOf(17-i);
}
JComboBox<String> batchComboBox = new JComboBox<>(batches);
batchComboBox.setBounds(100,220,50,20);
frame.add(batchComboBox);
JLabel positionLabel = new JLabel("Position:");
positionLabel.setBounds(10,250,100,20);
frame.add(positionLabel);
String[] positions = {"Preferred position","Goalkeeper","Sweeper","Centre Back","Full Back","Wing Back",
"Defensive Midfielder","Centre Midfielder","Wing Midfielder","Attacking Midfielder","Wing Forward","Centre Forward"};
JComboBox<String> positionComboBox = new JComboBox<>(positions);
positionComboBox.setBounds(100,250,160,20);
frame.add(positionComboBox);
JLabel pro = new JLabel("Did you play in inter-departmental tournaments?");
pro.setBounds(10,280,300,20);
frame.add(pro);
JRadioButton yes = new JRadioButton("Yes");
yes.setBounds(100,300,70,20);
frame.add(yes);
JRadioButton no = new JRadioButton("No");
no.setBounds(170,300,70,20);
frame.add(no);
ButtonGroup proGroup = new ButtonGroup();
proGroup.add(yes);
proGroup.add(no);
JLabel playingHistoryLabel = new JLabel("Experiences:");
playingHistoryLabel.setBounds(10,330,100,20);
frame.add(playingHistoryLabel);
JTextArea playingHistoryArea = new JTextArea();
playingHistoryArea.setBounds(100,330,200,60);
playingHistoryArea.setLineWrap(true);
playingHistoryArea.setWrapStyleWord(true);
frame.add(playingHistoryArea);
JLabel fileLabel = new JLabel("Profile Picture:");
fileLabel.setBounds(10,400,100,20);
frame.add(fileLabel);
JButton uploadButton = new JButton("Choose file");
uploadButton.setBounds(100,400,100,20);
frame.add(uploadButton);
JLabel filePathLabel = new JLabel("");
filePathLabel.setBounds(100,420,300,20);
frame.add(filePathLabel);
final String[] selectedFilePath = {""};
uploadButton.addActionListener(e -> {
JFileChooser fileChooser = new JFileChooser();
int returnValue = fileChooser.showOpenDialog(frame);
if(returnValue == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
selectedFilePath[0] = file.getAbsolutePath();
filePathLabel.setText(file.getName());
}
});
JButton submitButton = new JButton("Submit");
submitButton.setBounds(100,450,80,20);
frame.add(submitButton);
submitButton.addActionListener(e -> {
String username = usernameField.getText();
String email = emailField.getText();
String phone = String.valueOf(phoneField.getText());
String address = addressField.getText();
String gender = male.isSelected() ? "Male" : female.isSelected() ? "Female" : "Not Selected";
String dateOfBirth = dayComboBox.getSelectedItem()+" "+monthComboBox.getSelectedItem()+","+yearComboBox.getSelectedItem();
String degree = bsse.isSelected() ? "BSSE" : msse.isSelected() ? "MSSE" : "Not Selected";
String batch = (String)batchComboBox.getSelectedItem();
String position = (String)positionComboBox.getSelectedItem();
String isPro = yes.isSelected() ? "Yes" : no.isSelected() ? "No" : "Not Selected";
String playingHistory = playingHistoryArea.getText();
String photo = selectedFilePath[0].isEmpty() ? "Not uploaded" : selectedFilePath[0];
if(username.isEmpty() || email.isEmpty() || phone.isEmpty() || address.isEmpty() || gender.equals("Not Selected")
|| degree.equals("Not Selected") || position.equals("Preferred position") || isPro.equals("Not Selected")
|| playingHistory.isEmpty() || photo.equals("Not uploaded") ) {
JOptionPane.showMessageDialog(frame, "Please fill all the fields","Error",JOptionPane.ERROR_MESSAGE);
} else {
try {
FileWriter writer = new FileWriter("IIT_DU_Football_League_Data.txt",true);
writer.write("Username: " + username
+ "\nEmail: " + email
+ "\nPhone: " + phone
+ "\nAddress: " + address
+ "\nGender: " + gender
+ "\nDate of Birth: " + dateOfBirth
+ "\nDegree: " + degree
+ "\nBatch: " + batch
+ "\nPosition: " + position
+ "\nDid he play in inter-departmental tournaments?: " + isPro
+ "\nPlaying History: " + playingHistory
+ "\nPhoto: " + photo
+ "\n--------------------------------------------------------------------------\n"
);
writer.close();
JOptionPane.showMessageDialog(frame, "Registration Saved Successfully!", "Success", JOptionPane.INFORMATION_MESSAGE);
usernameField.setText("");
emailField.setText("");
phoneField.setText("");
addressField.setText("");
genderGroup.clearSelection();
dayComboBox.setSelectedIndex(0);
monthComboBox.setSelectedIndex(0);
yearComboBox.setSelectedIndex(0);
degreeGroup.clearSelection();
batchComboBox.setSelectedIndex(0);
positionComboBox.setSelectedIndex(0);
proGroup.clearSelection();
playingHistoryArea.setText("");
filePathLabel.setText("");
selectedFilePath[0] = "";
} catch (IOException exception) {
JOptionPane.showMessageDialog(frame, "Error writing to file!", "Error", JOptionPane.ERROR_MESSAGE);
exception.printStackTrace();
}
}
});
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}