Add a picture to a JFrame

前端 未结 3 1085
北恋
北恋 2021-01-29 17:02

All I am trying to do is add a picture to a JFrame.

I am really confused and don\'t really understand... I have looked up every possible question on this s

3条回答
  •  无人共我
    2021-01-29 17:11

    The biggest issues I can see are...

    • Extending from JFrame, but not actually using it...
    • Reliance on static when not really required...
    • Calling setVisible before anything has actually begin added. In fact, generally trying to manipulate the frame properties before anything was added to it and after it was made visible...

      public class Main {

       public static void main(String[] args){
      
           EventQueue.invokeLater(new Runnable() {
               public void run() {
      
                   JFrame xF = new JFrame("xFrame");
                   xF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   xF.add(new JLabel(new ImageIcon("/Clicker/xS/cow.png")));
                   xF.setResizable(false);
                   xF.setSize(WIDTH*SCALE,HEIGHT*SCALE);
                   xF.setLocationRelativeTo(null);
                   xF.setVisible(true);
      
                }
           }
       }
      

      }

    But since you never actually described what problems you were having, these are all guesses...

提交回复
热议问题