import
javax.swing.*;
import
java.awt.event.*;
import
java.awt.*;
class
imagecombo extends JFrame implements ItemListener
{
JComboBox jc1;
JPanel pane;
JLabel jl1;
public imagecombo()
{
super("Image Combo");
ImageIcon ii[];
ii=new ImageIcon[3];
jl1=new JLabel("Star");
int i;
for(i=1;i<=3;i++)
ii[i-1]=new
ImageIcon("u0"+i+".gif");
jc1=new JComboBox(ii);
pane=new JPanel();
pane.add(jc1);
pane.add(jl1);
setSize(200,200);
setContentPane(pane);
jc1.addItemListener(this);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void itemStateChanged(ItemEvent e)
{
switch(jc1.getSelectedIndex())
{
case 0:
jl1.setText("Star"); break;
case 1:
jl1.setText("Tree"); break;
case 2:
jl1.setText("Chair"); break;
}
}
public static void main(String args[])
{
imagecombo ic1=new imagecombo();
}
}
No comments:
Post a Comment