且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在JFrame表单中显示JPanel

更新时间:2023-12-05 08:25:28

- 不要在主要工作

- 做不要使用像Frame这样的关键字作为变量。

- 不要用大写字母开始变量名称 - 大写字母是对象名称,绝不是变量。



请将此链接加入书签: http://docs.oracle.com/javase/tutorial /uiswing/components/frame.html [ ^ ]



- Do NOT work in main
- Do NOT use keywords like "Frame" for variables.
- Do NOT start variable names with upper case - uppercase is an objects name, never a variable.

Please bookmark this link: http://docs.oracle.com/javase/tutorial/uiswing/components/frame.html[^]

public class MyForm extends JFrame{
     
        public MyForm(){
        
        this.init();
       
        }

        private void init(){
        // put code here and in other methods - not constructor
        }
        
    public static void main(String[] args) {
        // TODO code application logic here
        
        JFrame myFrame = new MyForm();
        myFrame.getContentPane().add(new JPanelFormInJFrameForm());
        myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        myFrame.setSize(300, 300);
    }
}


你做了所有事情,但忘了显示框架。

You did everything but forget to display the frame.
frame.setVisible(true);





该行应该在最后。



And the line should come at the end.