public class AddPlanePanel extends JPanel implements MyObserver
{
private JLabel planeLabel = new JLabel("New Plane ");
private JLabel nameForPlane = new JLabel("Name:");
public JTextField inputPlaneName = new JTextField(15);
private JButton button = new JButton("Add");
private JLabel status = new JLabel();
private JLabel typeLabel = new JLabel("Type:");
private String[] typeStrings = {"Antonov", "Cessna"};
private JComboBox typeList = new JComboBox(typeStrings);
private Planes planes;
public AddPlanePanel(Planes planes)
{
this.planes = planes;
planes.attach(this);
setup();
build();
}
private void setup()
{
setBorder(BorderFactory.createLineBorder(Color.blue));
planeLabel.setForeground(Color.magenta);
button.addActionListener(new Listener());
typeList.setEditable(true);
typeList.addActionListener(new Listener());
}
private void build()
{
add(planeLabel);
add(nameForPlane);
add(inputPlaneName);
add(typeLabel);
add(typeList);
add(button);
add(status);
}
public String name()
{
return inputPlaneName.getText();
}
public void update()
{
status.setText(name() + " added");
}
private class Listener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int type = Integer.parseInt((String)typeList.getSelectedItem());
planes.add(name(), type);
}
}
}
this is my code to add plane, i have problem at the JCombobox string array which is i need to convert string to int, so i can add the type to my plane.add method. specifically, the problem is in the actionPerformed that i cant change the value of the type which is string to int.
Thanks all.