我有一个用按钮填充的数组,我希望单个按钮在单击时更改其文本。
for (int i = 0; i<4; i++)
{
button[i] = new JButton ("Add");
button[i].addActionListener(this);
box[i] = new JComboBox();
foodOptions.add(box[i]);
foodOptions.add(button[i]);
}
public void actionPerformed (ActionEvent e)
{
button[this].setText("I've been clicked!");
}
当前由于类型不兼容而不起作用,什么格式合适?