4
回答
代码出错,求高手指点。跪谢!
注册华为云得mate10,2.9折抢先购!>>>   

 红色代码处报错,求高手指点。跪谢!

 

class ImagePreviewer extends JLabel
{
 /**
  * Constructs an ImagePreviewer.
  */
 
 public ImagePreviewer(JFileChooser chooser)
 {
  setPreferredSize(new Dimension(100,100));
  setBorder(BorderFactory.createEtchedBorder());
  
  chooser.addPropertyChangeListener(new PropertyChangeListener()
  {
   public void propertyChange(PropertyChangeEvent event)
   {
    if(event.getPropertyName()==JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)
    {
     //the user has selected a new file
     File f=(File)event.getNewValue();
     if(f==null);
     {
      setIcon(null);
      return;
     }
     //read the image into an icon
     ImageIcon icon = new ImageIcon (f.getPath());
    
     //if the icon is too large to fit,scale it
     
     if(icon.getIconWidth()>getWidth())icon=new ImageIcon(icon.getImage().getScaledInstance(getWidth(), -1, Image.SCALE_DEFAULT));
        setIcon(icon);
    }
   }
  });
 }
}

 

举报
Andy818
发帖于5年前 4回/188阅
顶部