Java &引用;从内部类引用的变量必须是final;问题
我正在创建一个代码,在Jbutton数组中有36个按钮Java &引用;从内部类引用的变量必须是final;问题,java,Java,我正在创建一个代码,在Jbutton数组中有36个按钮buttons[] 我使用一个循环为每个应用程序添加了一个动作侦听器 for (int ghe = 0; ghe < button.length; ghe++) { button[ghe].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { button[ghe].set
buttons[]
我使用一个循环为每个应用程序添加了一个动作侦听器
for (int ghe = 0; ghe < button.length; ghe++) {
button[ghe].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button[ghe].setVisible(false);
}
});
}
for(int-ghe=0;ghe
我希望单击的按钮不可见,但每次netbeans ide都会出现语法错误
从内部类引用的变量必须是final
我该怎么办?由于指定了您的方法,它将不起作用
ghe
属于int
类型,它不提供.setVisible
方法
我的解决方案是将该按钮从数组保存到一个变量中并使用它
for (int ghe = 0; ghe < button.length; ghe++)
{
JButton currentButton = button[ghe];
currentButton.addActionListener(e -> currentButton.setVisible(false));
}
for(int-ghe=0;ghecurrentButton.setVisible(false));
}
由于指定了您的方法,它将无法工作ghe
属于int
类型,它不提供.setVisible
方法
我的解决方案是将该按钮从数组保存到一个变量中并使用它
for (int ghe = 0; ghe < button.length; ghe++)
{
JButton currentButton = button[ghe];
currentButton.addActionListener(e -> currentButton.setVisible(false));
}
for(int-ghe=0;ghecurrentButton.setVisible(false));
}