我有这行代码,我想在添加乘客后禁用该按钮。我想禁用该按钮。seats[i].setEnabled(false)
由于它位于匿名内部类中,因此无法正常工作。
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.
}
});
}