package UI;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Practice implements ActionListener{
JFrame frame;
JComboBox combo;
JLabel lbl;
public Practice() {
frame=new JFrame("JComboBox Example");
frame.setSize(450,450);
frame.setLocationRelativeTo(null);
frame.setLayout(null);
String h1[]= {"Window1","Window2"};
combo=new JComboBox(h1);
combo.setBounds(10,10,150,25);
combo.addActionListener(this);
frame.add(combo);
lbl=new JLabel();
lbl.setBounds(10,50,100,25);
frame.add(lbl);
frame.setVisible(true);
}
public void actionPerformed (ActionEvent ae) {
if (ae.getSource()==combo) {
String h1=(String) combo.getSelectedItem();
lbl.setText(h1);
}
}
public static void main(String[] args) {
new Practice();
}
}