从JToggleButton数组获取值,但在if语句有问题的情况下检查[i] [j]。它说:“从内部类重新定义的局部变量必须是最终的或实际上是最终的” Return 1 to array check if time grid selected
private final JToggleButton[][] toggleButton;
private static final String[] days =
{"Monday","Tuesday","Wednesday","Thursday","Friday","Satuaday"};
private static final String[] times =
{"8:00","9:00","10:00","11:00","12:00","1:00","2:00","3:00","4:00"};
private final JLabel[] label;
private final GridLayout gridLayout;
private final int[][] check;
public ButtonFrame()
{
super("Testing");
setLayout(new FlowLayout());
gridLayout = new GridLayout(6,10);
setLayout(gridLayout);
toggleButton = new JToggleButton[6][9];
label = new JLabel[6];
check = new int[6][9];
for (int i = 0; i < toggleButton.length; i++)
{
label[i] = new JLabel(days[i]);
add(label[i]);
for (int j = 0; j < 9; j++)
{
toggleButton[i][j] = new JToggleButton(times[j],false);
ActionListener actionListener = new ActionListener()
{
public void actionPerformed(ActionEvent actionEvent)
{
AbstractButton abstractButton = (AbstractButton) actionEvent.getSource();
boolean selected = abstractButton.getModel().isSelected();
if (selected == true)
check[i][j] = 1;
else if (selected == false)
check[i][j] = 0;
}
};
// Attach Listeners
toggleButton[i][j].addActionListener(actionListener);
add(toggleButton[i][j]);
}
}
}
}
我想问如何解决这个问题