import javax.swing.*;  // JFrame
import java.awt.*; // container
import java.awt.event.*; // handlers
public class comboTest extends JFrame 
{
JTextField writeBox;
public comboTest()
   {
   setSize( 275, 100 );
   setDefaultCloseOperation(EXIT_ON_CLOSE);

   Container c = getContentPane();
   c.setLayout( new FlowLayout( ) ); 

   JButton exitButton = new JButton( "Exit" );
   c.add( exitButton );
   eventClass handler = new eventClass( );
   exitButton.addActionListener( handler );

   String names[ ] = {"stay", "leave", "ignore"};
   JComboBox myCombo = new JComboBox( names );
   c.add( myCombo);
   itemClass myComboHandler = new itemClass( );
   myCombo.addItemListener(myComboHandler);
   writeBox = new JTextField( "Hello" );
   c.add( writeBox );
   
   JButton writeButton = new JButton( "Write" );
   c.add( writeButton );
   
   writeButton.addActionListener( handler );
   writeBox.addActionListener( handler );

   setVisible(true);
   }
	 
public static void main (String [] args)
   {
   comboTest app = new comboTest();
   }
   
private class eventClass implements ActionListener 
   {
   public void actionPerformed ( ActionEvent e ) 
      {
  		if (e.getActionCommand().equals("Exit"))
		   {
			System.exit(0); 
			} 
		if (e.getActionCommand().equals("Write"))
		   {
			System.out.println( writeBox.getText() );
			} 	 	 
      } // end actionPerformed method
   } // end private class

private class itemClass implements ItemListener
   {
   public int times = 1;
   public void itemStateChanged( ItemEvent x )
      {
		System.out.println("times: " + times);
		// handle every OTHER action (that is, selection not DEselection)
		if (times == 1)
		   {
			times++;
			}
   	else
		   {
			times = 1;
			System.out.println( x.getItem( ) );
			writeBox.setText( x.getItem().toString() );
			}    
		}
   } // end inner class
   
} // end class

