这是我有错误的代码:
pic = new ImageIcon("Koala.jpg");
picArr = ImageUtil.sliceImage(3, 3, pic);
for (int i = 0; i < picArr.length; i++){
leftbut[i].setIcon(new ImageIcon(picArr[i]));
}
这是确切的错误行:
leftbut[i].setIcon(new ImageIcon(picArr[i]));
这是错误:
no suitable constructor found for ImageIcon(ImageIcon)
constructor ImageIcon.ImageIcon() is not applicable
(actual and formal argument lists differ in length)
constructor ImageIcon.ImageIcon(byte[]) is not applicable
(actual argument ImageIcon cannot be converted to byte[] by method invocation conversion)
constructor ImageIcon.ImageIcon(byte[],String) is not applicable
(actual and formal argument lists differ in length)
constructor ImageIcon.ImageIcon(Image) is not applicable
(actual argument ImageIcon cannot be converted to Image by method invocation conversion)
constructor ImageIcon.ImageIcon(Image,String) is not applicable
(actual and formal argument lists differ in length)
constructor ImageIcon.ImageIcon(URL) is not applicable
(actual argument ImageIcon cannot be converted to URL by method invocation conversion)
constructor ImageIcon.ImageIcon(URL,String) is not applicable
(actual and formal argument lists differ in length)
constructor ImageIcon.ImageIcon(String) is not applicable
(actual argument ImageIcon cannot be converted to String by method invocation conversion)
constructor ImageIcon.ImageIcon(String,String) is not applicable
(actual and formal argument lists differ in length)
附加信息-leftbut。[i]是9个按钮的数组,我想通过使用上述方法在1个按钮上设置imageicon并将1个图像切成9 peices请帮助我。谢谢!
最佳答案
这个leftbut[i].setIcon(new ImageIcon(picArr[i]));
应该是这个leftbut[i].setIcon(picArr[i]);