我想我已经把自己写成了一个角落.我正在尝试使用java swing做这个效果.
单击下一步按钮,从文件中加载一个新行(通过行索引号),然后如果文件中的行的日期尚未到达,则使下一个按钮变灰.我的问题是,当我有以下代码时:
Scanner input = new Scanner(System.in);
System.out.println("Enter week number");
int j = input.nextInt();
String[] strArray = new String[4];
xmlLoader(j, strArray);
JButton nextButton = new JButton("Next");
nextButton.setBounds(750, 250, 80, 30);
nextButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
j++;
doNext(j, nextButton);
}
});
Run Code Online (Sandbox Code Playgroud)
我不能通过j,因为它不是最终的,如果它是最终的,我无法改变按钮上的任何东西,helpppp!
特定错误:从内部类中访问局部变量j; 需要宣布最终
您可以将其定义j为外部类中的字段.
class Sample{
private int j;
void method() {
...
nextButton.setBounds(750, 250, 80, 30);
nextButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
j++;
doNext(j, nextButton);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13110 次 |
| 最近记录: |