Java adding ImageIcon to JLabel

后端 未结 3 1545
悲&欢浪女
悲&欢浪女 2021-02-15 14:14

I am trying to make a very basic game with Java and I am having trouble displaying an image on a JFrame. It has worked in the past for me and now is not, i can\'t s

3条回答
  •  长发绾君心
    2021-02-15 14:45

    Your problem lies here:

       ImageIcon image = new ImageIcon("C:/Documents and Settings/user/Desktop/hi/xD/JavaApplication2/image.png");
       JLabel imagelabel = new JLabel(character);
    

    You create an ImageIcon "image" but you create your JLabel with "character".

    It should be:

    JLabel imagelabel = new JLabel(image);
    

提交回复
热议问题