构造函数中生成的数组怎么在内部类使用?

Craftsman98 2018-11-25 10:32:30
public class Line1 extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;



public Line1(String[] array, String title) {
String[] station;
station = array;
JButton[] stationButton1 = new JButton[station.length];

Container container = getContentPane();
setLayout(new GridLayout(6, 5,10,10));
for (int i = 0; i < station.length; i++ ) {
stationButton1[i] = new JButton(station[i]);
container.add(stationButton1[i]);
}
setSize(800, 600);
setTitle(title);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}




public class stationSelect implements ActionListener{

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int index = new PrintArray(stationButton1, e).getIndex(); //这里stationButton1会报错


}

}

}

怎样让stationButton1数组能够在内部类中使用?小菜鸟刚刚学习java,请各位大佬指导
...全文
36 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_39936465 2018-11-26
  • 打赏
  • 举报
回复
变量定义的范围问题,如果变量是几个内部类中都要使用的,整个类中定义而不是单独在某个类中定义
nayi_224 2018-11-26
  • 打赏
  • 举报
回复
定义提到外面

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧