-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombobox.java
More file actions
39 lines (32 loc) · 930 Bytes
/
combobox.java
File metadata and controls
39 lines (32 loc) · 930 Bytes
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
package mayank;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class combobox extends JFrame {
private JLabel picture;
private JComboBox box;
private static String[] filename={"b.png","x.png"};
private Icon[] pics={new ImageIcon(getClass().getResource(filename[0])),new ImageIcon(getClass().getResource(filename[1]))};
public combobox(){
super("the title bar");
setLayout(new FlowLayout());
box=new JComboBox (filename);
box.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent event) {
if(event.getStateChange()==ItemEvent.SELECTED)
picture.setIcon(pics[box.getSelectedIndex()]);
}
}
);
add(box);
picture=new JLabel(pics[0]);
add(picture);
}
public static void main(String[] args) {
combobox ob=new combobox();
ob.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ob.setVisible(true);
ob.setSize(300,300);
}
}