-
Notifications
You must be signed in to change notification settings - Fork 0
/
Combobox.java
37 lines (31 loc) · 1.03 KB
/
Combobox.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
package ComboBox;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Combobox extends JFrame {
Combobox(){
final JLabel label = new JLabel();
label.setHorizontalAlignment(JLabel.CENTER);
label.setSize(400,100);
String[] lang = {"JAVA","PHP","PYTHON","C++","RUST"};
final JComboBox c = new JComboBox(lang);
c.setBounds(40,90,100,40);
JButton btn = new JButton("Show");
btn.setBounds(180,90,90,25);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String cp = "Programming name selected: "+c.getItemAt(c.getSelectedIndex());
label.setText(cp);
}
});
add(label);add(c);
add(btn);
setLayout(null);
setVisible(true);
setSize(500,500);
}
public static void main(String[] args) {
new Combobox();
}
}