调整ImageIcon的大小



我试图调整我的图像,以适应我的java屏幕,但我一直得到这个错误标记语法错误";",,预期">

代码也不多:

import java.awt.Image;
import javax.swing.ImageIcon;
public class Images 
{
ImageIcon welcomeImage = new ImageIcon("WelcomeImage.PNG");
Image image = welcomeImage.getImage();
Image newImage = image.getScaledInstance(750, 500, java.awt.Image.SCALE_SMOOTH);//The error appears on this line
welcomeImage = new ImageIcon(newImage);

}

您需要将代码放在方法中,而不是直接放在类定义中。

试试这个例子:

import java.awt.Image;
import javax.swing.ImageIcon;
public class Images 
{
public static void main(String[] args) {
ImageIcon welcomeImage = new ImageIcon("WelcomeImage.PNG");
Image image = welcomeImage.getImage();
Image newImage = image.getScaledInstance(750, 500, java.awt.Image.SCALE_SMOOTH);//The error appears on this line
welcomeImage = new ImageIcon(newImage);
}
}

相关内容

  • 没有找到相关文章

最新更新