- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElection.java
More file actions
Latest commit
55 lines (48 loc) · 1.96 KB
/
Copy pathElection.java
File metadata and controls
55 lines (48 loc) · 1.96 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
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
publicclassElectionextendsJFrame {
privateJLabellblName, lblVoterID, lblpincode, lblParty;
privateJTextFieldtxtName, txtVoterID, txtpincode;
privateJComboBox<String> partyComboBox;
privateJButtonsubmitButton;
publicElection() {
setTitle("Election Booth 2024");
setSize(200, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(newGridLayout(6, 2));
lblName = newJLabel("Enter your name: ");
txtName = newJTextField();
lblVoterID = newJLabel("Enter your voter ID: ");
txtVoterID = newJTextField();
lblpincode = newJLabel("Enter your city pincode: ");
txtpincode = newJTextField();
lblParty = newJLabel("Choose your party: ");
String[] parties = {"party 1", "party 2", "party 3"};
partyComboBox = newJComboBox<>(parties);
submitButton = newJButton("Submit");
submitButton.addActionListener(e -> VotingForm());
add(lblName);
add(txtName);
add(lblVoterID);
add(txtVoterID);
add(lblpincode);
add(txtpincode);
add(lblParty);
add(partyComboBox);
add(newJLabel());
add(submitButton);
setVisible(true);
}
privatevoidVotingForm() {
Stringname = txtName.getText();
Stringvoter_id = txtVoterID.getText();
intpincode = Integer.parseInt(txtpincode.getText());
Stringparty = (String) partyComboBox.getSelectedItem();
// Displaying the details
JOptionPane.showMessageDialog(this, "Name: " + name + "\nVoter ID: " + voter_id + "\nPincode: " + pincode + "\nParty: " + party + "\n\nYour vote is successful.", "Vote Confirmation", JOptionPane.INFORMATION_MESSAGE);
}
publicstaticvoidmain(String[] args) {
SwingUtilities.invokeLater(() -> newElection());
}
}