public class PersonalData extends JFrame implements ActionListener
{
//Initialize Array
String zipCode[] = {"38001", "38006", "38343", "38305", "38301"};
String states[] = {"AL", "AK","AZ","AR","CA","CO","CT","DE","FL","GA","GU","HI","ID","IL","IN","IA","KS","KY","LA","MA","MD","MS","MI","MN","MI","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","PR","RI","SC","SD","TN","TX","UT","VT","VI","VA","WA","WV","WI","WY"};
//Construct a panel for each row
JPanel firstRow = new JPanel();
JPanel secondRow = new JPanel();
JPanel thirdRow = new JPanel();
JPanel fourthRow = new JPanel();
JPanel fifthRow = new JPanel();
JPanel sixthRow = new JPanel();
//Construct Components
JComboBox zipCombo = new JComboBox(zipCode);
JComboBox stateCombo = new JComboBox(states);
//Construct a panel for the fields and buttons
JPanel fieldPanel = new JPanel();
//Construct labels and text boxes
JLabel firstNameLabel = new JLabel("First Name:");
JTextField firstName = new JTextField(20);
JLabel lastNameLabel = new JLabel("Last Name:");
JTextField lastName= new JTextField(20);
JLabel addressLabel = new JLabel("Address:");
JTextField address = new JTextField(30);
JLabel cityLabel = new JLabel("City:");
JTextField city = new JTextField(10);
JLabel stateLabel = new JLabel("State:");
JTextField state = new JTextField(2);
JLabel zipLabel = new JLabel("Zip:");
JTextField zip = new JTextField(9);
//Construct Button
JButton submitButton = new JButton("Submit");
//Create Content Pane
public void createContentPane()
{
//Populate the JComboBox
stateCombo.addActionListener(this);
zipCombo.addActionListener(this);
[B]zipCombo.setEditable(true);[/B]
}
public static void main(String args[])
{
PersonalData f= new PersonalData();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(500,400);
f.setTitle("Personal Data");
f.setResizable(false);
f.setLocation(200,200);
f.setVisible(true);
}
public PersonalData()
{
Container c = getContentPane();
c.setLayout((new BorderLayout()));
fieldPanel.setLayout(new GridLayout(8,1));
FlowLayout rowSetup = new FlowLayout(FlowLayout.LEFT,5,0);
firstRow.setLayout(rowSetup);
secondRow.setLayout(rowSetup);
thirdRow.setLayout(rowSetup);
fourthRow.setLayout(rowSetup);
//Add fields to rows
firstRow.add(firstNameLabel);
firstRow.add(firstName);
secondRow.add(lastNameLabel);
secondRow.add(lastName);
thirdRow.add(addressLabel);
thirdRow.add(address);
fourthRow.add(cityLabel);
fourthRow.add(city);
fourthRow.add(stateLabel);
fourthRow.add(stateCombo);
fourthRow.add(zipLabel);
fourthRow.add(zipCombo);
fifthRow.add(submitButton);
//Add rows to panel
fieldPanel.add(firstRow);
fieldPanel.add(secondRow);
fieldPanel.add(thirdRow);
fieldPanel.add(fourthRow);
fieldPanel.add(fifthRow);
fieldPanel.add(sixthRow);
//Add panels to frame
c.add(fieldPanel, BorderLayout.CENTER);
//Add functionality to button
submitButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
//user clicks the combo box
if (e.getSource() == stateCombo);
if (e.getSource() == zipCombo);
}
}