0

这是我遇到错误的代码:

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 个按钮的数组,我想通过使用上述方法在每个按钮上设置 imageicon 并将 1 个图像切成 9 个 peices 请帮助我。谢谢!

4

1 回答 1

4

这个

leftbut[i].setIcon(new ImageIcon(picArr[i]));

应该是这个

leftbut[i].setIcon(picArr[i]);

于 2013-01-28T05:07:01.263 回答