import javax.swing.*;public class useJFrame {
  JFrame mainFrame;
  JLabel myJLabel;
  public useJFrame() {
    mainFrame=new JFrame("JFrame演示窗口");
    myJLabel=new JLabel("世界,你好");
    mainFrame.getContentPane().setLayout(new FlowLayout());//设置布局
     mainFrame.getContentPane().add(myJLabel);  //注意这种添加组件的方法
    mainFrame.pack();
    mainFrame.setVisible(true);
  mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }  public static void main(String[] args) {
    new useJFrame();
  }
}

解决方案 »

  1.   

    和这种添加组件的方法有什么不同
    mainFrame.add(myJLabel); 
      

  2.   

    public class useJFrame {
      JFrame mainFrame;
      JLabel myJLabel;
      public useJFrame() {
      mainFrame=new JFrame("JFrame演示窗口");
      myJLabel=new JLabel("世界,你好");
      mainFrame.getContentPane().setLayout(new FlowLayout());//设置布局
      mainFrame.getContentPane().add(myJLabel); //注意这种添加组件的方法
      mainFrame.pack();
      mainFrame.setVisible(true);
      mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }  public static void main(String[] args) {
      new useJFrame();
      }
    }
      

  3.   

    请参阅 The Java Tutorial 中的 How to Make Frames 一节。