Adding JPanel to JFrame

后端 未结 5 1687
长情又很酷
长情又很酷 2021-02-06 04:24

I have a program in which a JPanel is added to a JFrame:

public class Test{

    Test2 test = new Test2();
    JFrame frame = new JFrame();

    Test(){

    ...         


        
5条回答
  •  不要未来只要你来
    2021-02-06 04:33

    public class Test{
    
    Test2 test = new Test2();
    JFrame frame = new JFrame();
    
    Test(){
    ...
    frame.setLayout(new BorderLayout());
    frame.add(test, BorderLayout.CENTER);
    ...
    }
    
    //main
    ...
    }
    
    //public class Test2{
    public class Test2 extends JPanel {
    
    //JPanel test2 = new JPanel();
    
    Test2(){
    ...
    }
    

提交回复
热议问题