 |
|
|
TestGUI.java
|
/*
* Author: Havard Rast Blok
* E-mail: 
* Web : www.rememberjava.com
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* Draws a simple GUI with a JComboBox and a JTextField.
*/
public class TestGUI extends JFrame implements ItemListener
{
private String artists[] = {"Astral Projection", "Man With No Name", "A Reminiscent Drive"};
private Container c;
private JComboBox comboBox;
private JTextField textField;
public TestGUI()
{
super( "Test GUI" );
//set up GUI
setSize(200, 150);
c = getContentPane();
c.setLayout( new GridLayout( 2, 1 ) );
textField = new JTextField();
comboBox = new JComboBox( artists );
comboBox.addItemListener( this );
c.add( textField );
c.add( comboBox );
pack();
show();
}
public void itemStateChanged(ItemEvent e)
{
textField.setText( ""+e.getItem() );
}
public static void main( String [] arg)
{
new TestGUI();
}// end main
}
|
|
|
 |