-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSwingComboBox.java
46 lines (38 loc) · 1.2 KB
/
SwingComboBox.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
package src.uni.lessons.jswing;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class SwingComboBox extends JFrame {
JComboBox<String> comboBox;
public SwingComboBox(String title) {
super(title);
}
public void init() {
setSize(200, 200);
setVisible(true);
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
comboBox = new JComboBox<>();
comboBox.addItem("INSERT");
comboBox.addItem("DELETE");
comboBox.addItem("UPDATE");
comboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println(comboBox.getSelectedIndex());
int i = comboBox.getSelectedIndex();
System.out.println(i);
}
});
add(comboBox);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SwingComboBox("Combobox").init();
}
});
}
}