import javax.swing.*; import java.awt.*; import java.awt.event.*;
public class ComboBox{ JComboBox combo; JTextField txt; public static void main(String[] args) { ComboBox b = new ComboBox(); }
public ComboBox(){ String course[] = {"BCA","MCA","PPC","CIC"}; // string using in array JFrame frame = new JFrame("Creating a JComboBox Component");//method JPanel panel = new JPanel();//panel combo = new JComboBox(course); // combo box method combo.setBackground(Color.gray); combo.setForeground(Color.red); txt = new JTextField(10); panel.add(combo); panel.add(txt); frame.add(panel); combo.addItemListener(new ItemListener(){ public void itemStateChanged(ItemEvent ie){ String str = (String)combo.getSelectedItem(); txt.setText(str); } }); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// exit on close frame.setSize(400,400);//frame size frame.setVisible(true); } } |
0 comments:
Post a Comment