Kiran Kumar
Posts: 12
Nickname: k3
Registered: May, 2007
|
|
Re: Importing value in textbox when an item is selected in the combobox
|
Posted: May 29, 2007 1:35 AM
|
|
import javax.swing.*; import java.awt.*; import java.awt.event.*;
public class ComboProblem extends JFrame{
private JComboBox myCombo; private JTextField myText; ComboProblem(){ super("C O M B O");
myText = new JTextField(); add( BorderLayout.CENTER, myText); Object []items = { "Select a Language", "Java", "C++", "SmallTalk", "Python" }; myCombo = new JComboBox( items ); myCombo.addActionListener( new ActionListener(){ public void actionPerformed( ActionEvent e ){ Object obj = ((JComboBox)e.getSource()).getSelectedItem(); myText.setText( obj.toString() ); } }); add( BorderLayout.NORTH, myCombo ); setDefaultCloseOperation( EXIT_ON_CLOSE ); setBounds( 10, 20, 300, 100 ); setVisible( true ); } public static void main(String[] args) { new ComboProblem(); }
}
|
|