package UI;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Practice implements ItemListener{
JFrame frame;
JComboBox combo;
JTextField combotxt;
public Practice() {
frame=new JFrame("JComboBox Example");
frame.setSize(450,450);
frame.setLocationRelativeTo(null);
frame.setLayout(null);
String h1[]= {"Hancie","Nitesh"};
combo=new JComboBox(h1);
combo.setBounds(10,10,150,25);
combo.addItemListener(this);
frame.add(combo);
combotxt=new JTextField();
combotxt.setBounds(10,50,150,25);
frame.add(combotxt);
frame.setVisible(true);
}
public void itemStateChanged (ItemEvent ae) {
if (ae.getSource()==combo) {
String h1=(String) combo.getSelectedItem();
combotxt.setText(h1);
}
}
public static void main(String[] args) {
new Practice();
}
}