我想把我的java游戏的图标设置成一个叫lgico.png的图标,但是当我用。static ImageIcon icon = new ImageIcon("lgico.png");

public Window(int width, int height, String title, Game game) {
frame.setIconImage(icon.getImage());
}

我的jar文件没有图标 当我创建它并把它放在我的桌面上。

这是我的窗口类的全部内容。package com.teto.main;

import java.awt.Canvas;
import java.awt.Cursor;
import java.awt.Dimension;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class Window extends Canvas {
private static final long serialVersionUID = 5486926782194361510L;
static ImageIcon icon = new ImageIcon("lgico.png");
Cursor csr = new Cursor(Cursor.CROSSHAIR_CURSOR);
public Window(int width, int height, String title, Game game) {
JFrame frame = new JFrame(title);
frame.setPreferredSize(new Dimension(width, height));
frame.setMaximumSize(new Dimension(width, height));
frame.setMinimumSize(new Dimension(width, height));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.add(game);
frame.setVisible(true);
frame.setIconImage(icon.getImage());
frame.setCursor(csr);
game.start();
}
}

我曾多次在这个网站上寻找解决方法 但结果都是NullPointerException异常 我的程序是一个白屏,上面什么都没有。

如果我想表达的内容看起来不是很清楚,我很抱歉,因为我的母语不是英语。