-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElection.java
55 lines (48 loc) · 1.96 KB
/
Election.java
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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Election extends JFrame {
private JLabel lblName, lblVoterID, lblpincode, lblParty;
private JTextField txtName, txtVoterID, txtpincode;
private JComboBox<String> partyComboBox;
private JButton submitButton;
public Election() {
setTitle("Election Booth 2024");
setSize(200, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new GridLayout(6, 2));
lblName = new JLabel("Enter your name: ");
txtName = new JTextField();
lblVoterID = new JLabel("Enter your voter ID: ");
txtVoterID = new JTextField();
lblpincode = new JLabel("Enter your city pincode: ");
txtpincode = new JTextField();
lblParty = new JLabel("Choose your party: ");
String[] parties = {"party 1", "party 2", "party 3"};
partyComboBox = new JComboBox<>(parties);
submitButton = new JButton("Submit");
submitButton.addActionListener(e -> VotingForm());
add(lblName);
add(txtName);
add(lblVoterID);
add(txtVoterID);
add(lblpincode);
add(txtpincode);
add(lblParty);
add(partyComboBox);
add(new JLabel());
add(submitButton);
setVisible(true);
}
private void VotingForm() {
String name = txtName.getText();
String voter_id = txtVoterID.getText();
int pincode = Integer.parseInt(txtpincode.getText());
String party = (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);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new Election());
}
}