Monday, 15 October 2012

java Combo Box

 
//JComboBox Demo
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/*
<applet code="JComboBoxDemo" width=300 height=100>
</applet>
*/

public class JComboBoxDemo extends JApplet
implements ItemListener {

JLabel jl;
ImageIcon Flowers, Koala, Desert, Penguins, sateesh;

public void init(){
// Get content pane
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());

// Create a Combo box and add it
//to the pane
JComboBox jc = new JComboBox();
jc.addItem("Flowers");
jc.addItem("Koala");
jc.addItem("Desert");
jc.addItem("Penguins");
jc.addItem("sateesh");
jc.addItemListener(this);
contentPane.add(jc);

//Create label
jl = new JLabel(new ImageIcon("Flowers.gif"));
contentPane.add(jl);
}

public void itemStateChanged(ItemEvent ie) {
String s = (String)ie.getItem();
jl.setIcon(new ImageIcon(s +".gif"));
}
}