我想将4个JPanel添加到我拥有的JApplet中,并为每个人提供不同的颜色.但没有显示任何颜色 - 我的意思是我看不到输出.根本没有颜色.以下代码在init()方法中.
this.setSize(1400, 780);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setLayout(null) ;
setLayout(null) ;
Panel1 = new JPanel() ;
Panel2 = new JPanel () ;
Panel3 = new JPanel() ;
Panel4 = new JPanel() ;
Label1 = new JLabel ("Label1") ;
Label2 = new JLabel ("Label2") ;
Label3 = new JLabel ("Label3") ;
Label4 = new JLabel ("Label4") ;
Panel1.add(Label1) ;
Panel2.add(Label2) ;
Panel3.add(Label3) ;
Panel4.add(Label4) ;
// Panel 1 "About Me"
Panel1.setSize(140,390) ;
Panel1.setLocation(0,0) ;
Panel1.setBackground(Color.red) ;
Panel1.setVisible(true) ; …Run Code Online (Sandbox Code Playgroud)