import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Font.*;
import java.awt.Dimension.*;
public class ComboBox implements ItemListener
{
/*** Class Variables ***/
private String[] boxOptions = new String[ 3 ];
private JPanel[] boxDisplays = new JPanel[ 3 ];
private JComboBox cmbxDoorType;
private JPanel createDoubleDoorDisplay;
private JPanel createSingleDoorOptions;
private JPanel createDoubleDoorOptions;
/*** Constructor ***/
public ComboBox( JPanel pCreateDoubleDoorDisplay,
JPanel pCreateSingleDoorOptions,
JPanel pCreateDoubleDoorOptions,
String pBoxOption1,
String pBoxOption2,
String pBoxOption3)
{
createDoubleDoorDisplay = pCreateDoubleDoorDisplay;
createDoubleDoorDisplay.setVisible( false );
createSingleDoorOptions = pCreateSingleDoorOptions;
createSingleDoorOptions.setVisible( false );
createDoubleDoorOptions = pCreateDoubleDoorOptions;
createDoubleDoorOptions.setVisible( false );
}
/*** Accessors ***/
public String[] getBoxOptions()
{
return boxOptions;
}
public JPanel[] getBoxDisplays()
{
return boxDisplays;
}
/*** Mutators/Transformers ***/
public void setBoxOptions( String pBoxOptions, int pInt )
{
boxOptions[ pInt ] = pBoxOptions;
}
public void setBoxDisplays( JPanel pBoxDisplays, int pInt )
{
boxDisplays[ pInt ] = pBoxDisplays;
pBoxDisplays.setVisible( true );
}
public JComboBox createComboBox( String pBoxOption1,
String pBoxOption2,
String pBoxOption3 )
{
setBoxOptions( pBoxOption1, 0 );
setBoxOptions( pBoxOption2, 1 );
setBoxOptions( pBoxOption3, 2 );
cmbxDoorType = new JComboBox( boxOptions ); // JComboBox is Deprecated.
cmbxDoorType.addItemListener( this );
return cmbxDoorType;
}
public void itemStateChanged( ItemEvent e )
{
if ( e.getStateChange() == ItemEvent.SELECTED )
{
if ( boxDisplays[ cmbxDoorType.getSelectedIndex() ].equals( 0 ) )
{
setBoxDisplays( createDoubleDoorDisplay, 0 );
createDoubleDoorDisplay.setVisible( true );
}
else if ( boxDisplays[ cmbxDoorType.getSelectedIndex() ].equals( 1 ) )
{
setBoxDisplays( createSingleDoorOptions, 1 );
createSingleDoorOptions.setVisible( true );
}
else if ( boxDisplays[ cmbxDoorType.getSelectedIndex() ].equals( 2 ) )
{
setBoxDisplays( createDoubleDoorOptions, 2 );
createDoubleDoorOptions.setVisible( true );
}
}
}
}