【发布时间】:2011-06-12 09:52:59
【问题描述】:
我有这行代码,我想在添加乘客后禁用该按钮。我想禁用该按钮。 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.
}
});
}
【问题讨论】:
标签: java class anonymous-inner-class