我正在使用createAndShowGUI()
方法创建一个JFrame
。我想设置一个图标,但是当我在NetBeans中运行它时,它不显示。然而,当我运行包含图像的.jar
文件(与图像位于同一文件夹中)时,则可以无缺陷地工作。
private static void createAndShowGUI() {
//Create and set up the window.
JFrame game = new JFrame();
game.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
game.setSize(198, 409);
game.setResizable(false);
game.setTitle("Frame Title");
ImageIcon img = new ImageIcon("Icon.png");
game.setIconImage(img.getImage());
game.setVisible(true);
}
有没有任何想法,问题可能出在哪里?