-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplayMenu.java
More file actions
83 lines (68 loc) · 2.04 KB
/
displayMenu.java
File metadata and controls
83 lines (68 loc) · 2.04 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
package project;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.util.concurrent.CountDownLatch;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
class displayMenu extends JFrame {
static int idx = -1;
CountDownLatch latch = new CountDownLatch(1);
JFrame f;
displayMenu(LinkedList<Node> ptr) {
latch = new CountDownLatch(1);
new JFrame("Button Centered Example");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenResolution = new Dimension(toolkit.getScreenSize());
setSize(screenResolution);
setTitle("Select Your Choice");
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(8,8,8,8);
int i = 1;
gbc.gridx = 0;
gbc.gridy = 0;
JPanel jp = new JPanel(new GridBagLayout());
for (Node a : ptr) {
JButton b = new JButton(i + ") " + a.data);
b.setPreferredSize(new Dimension(350, 70));
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JButton clickedButton = (JButton) e.getSource();
Character choice = clickedButton.getText().charAt(0);
String a = choice.toString();
displayMenu.idx = Integer.parseInt(a);
setVisible(false);
latch.countDown();
}
});
b.setBackground(new Color(44, 59, 87));
b.setForeground(new Color(197, 221, 232));
jp.add(b, gbc);
gbc.gridy = i++;
}
LineBorder lb = new LineBorder(new Color(15, 8, 61), 6);
jp.setBorder(lb);
jp.setBackground(new Color(197, 221, 235));
add(jp, BorderLayout.CENTER);
setVisible(true);
try {
// Wait for the user to click the button
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
int getIndex() {
return idx;
}
}