I have these line of code and I want to disable the button after a passenger has been added. I want to disable the button. seats[i].setEnabled(false)
won't work since it's inside an anonymous inner class.
JButton [] seats = new JButton [40]; //creating a pointer to the buttonsArray
for (int i = 0; i < 40; i++)
{
seats[i] = new JButton();//creating the buttons
seats[i].setPreferredSize(new Dimension(50,25));//button width
panel4seating.add(seats[i]);//adding the buttons to the panels
final int seatingID = i; // Create a local final variable so it can be passed to the anonymous innerClass...
seats[i].addActionListener(new ActionListener()
{ //anonymous inner class
public void actionPerformed(ActionEvent evt)
{
String firstName = showInputDialog();
String lastName = showInputDialog();
sw101.AddPassenger(firstName, lastName, seatingID);//adding a pasenger
//I want to add a line here that disables the button.
}
});
}