-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyFrame3.java
More file actions
50 lines (39 loc) · 1.42 KB
/
MyFrame3.java
File metadata and controls
50 lines (39 loc) · 1.42 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
import java.awt.EventQueue;
import java.awt.GridLayout;
import javax.swing.*;
import java.net.*;
import java.io.*;
import java.text.*;
import java.util.*;
public class MyFrame3{
public static String output;
private static HashMap<String,String> CandidateTable;
public static JPanel panel = new JPanel(new GridLayout(0, 1));
public MyFrame3(HashMap<String,String> CandidateTable){
this.CandidateTable = CandidateTable;
}
public static void display(){
JTextField field1 = new JTextField();
JTextField field2 = new JPasswordField();
panel.add(new JLabel("Enter Name of Candidate you wish to vote for . Must be exactly as mentioned in the list.\n"));
printMenu(CandidateTable);
panel.add(field1);
int result = JOptionPane.showConfirmDialog(null, panel, "Test",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
output = field1.getText();
} else {
System.out.println("Cancelled");
}
}
public static String getOutput(){
return output;
}
public static void printMenu(HashMap<String,String> CandidateTable){
int i = 1;
for (String item: CandidateTable.keySet()) {
panel.add(new JLabel(Integer.toString(i) + " : " + item));
i++;
}
}
}