これらのコード行があり、乗客が追加された後にボタンを無効にしたいと考えています。ボタンを無効にしたい。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.
}
});
}