JButton[] forButtons = new JButton[5]{grayButton,ZhifangButton,lianTongYu};
这样怎么初始化不成功??
------解决方案--------------------
- Java code
JButton[] forButtons = new JButton[]{grayButton,ZhifangButton,lianTongYu};
------解决方案--------------------
把5 去掉。
如果你一定要初始化length为5的数组,
则在后面加两个null,null吧。
------解决方案--------------------
既然是JButton类型数组 那么数组元素也必须的是JButton类型
------解决方案--------------------
楼上的说的对
JButton[] forButtons = new JButton[]{grayButton,ZhifangButton,lianTongYu};
或者
JButton[] forButtons = new JButton[5]{grayButton,ZhifangButton,lianTongYu,null,null};
------解决方案--------------------
JButton[] forButtons = new JButton[]{grayButton,ZhifangButton,lianTongYu};
楼上说的都没错,这个叫做静态初始化,系统会依据你给的数据数据的个数来自动帮你确定数组的大小。
------解决方案--------------------
JButton[] forButtons = new JButton[]{grayButton,ZhifangButton,lianTongYu,null,null};
JButton[] forButtons = new JButton[5];
JButton[] forButtons = {grayButton,ZhifangButton,lianTongYu,null,null};
这些都是合法的初始化
------解决方案--------------------