-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComboBoxEg.java
45 lines (35 loc) · 954 Bytes
/
ComboBoxEg.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
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.JOptionPane;
public class ComboBoxEg implements ActionListener{
JComboBox cb;
JFrame f;
ComboBoxEg() {
f=new JFrame();
cb=new JComboBox();
String[] animal= {"hathi","ghora","uth","billi"};
cb=new JComboBox(animal);
cb.addActionListener(this);
//cb.setEditable(true);
//cb.setSelectedIndex(0);
cb.addItem("kutta");
cb.insertItemAt("ullu",0);
f.add(cb);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new FlowLayout());
f.pack();
f.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==cb) {
JOptionPane.showMessageDialog(f,cb.getSelectedItem());
}
}
public static void main(String[] args) {
new ComboBoxEg();
}
}