我有点卡住了。为什么这行不通?我只是收到一条错误消息:
java.lang.NoSuchMethodError: main
Exception in thread "main"
import java.awt.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class ShowPNG extends JFrame
{
public void main(String arg)
{
if (arg == null ) {
arg = "C:/Eclipse/workspace/ShowPNG/bin/a.png";
}
JPanel panel = new JPanel();
panel.setSize(500,640);
panel.setBackground(Color.CYAN);
ImageIcon icon = new ImageIcon(arg);
JLabel label = new JLabel();
label.setIcon(icon);
panel.add(label);
this.getContentPane().add(panel);
this.setVisible(true);
}
}
最佳答案
你的主要方法应该是:
public static void main(String[] args)
关于java - 在 JFrame 中显示 .png 图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4160904/