package com;
import javax.swing.*;
import java.awt.*;
public class A {
public static void main(String arg[]){
JPanel j=new JPanel();
j.setBackground(Color.pink);
JButton b=new JButton("请按");
j.add(b);
JFrame f=new JFrame("主题");
JLabel l=new JLabel("我的我的");
Container c=f.getContentPane();
c.add(j,BorderLayout.CENTER);
f.getContentPane().add(l,BorderLayout.CENTER);
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.setLocation(600,400);
f.setSize(400,400);
f.setVisible(true);
}
}
新手小白,不太懂,新学的(很好奇为啥背景颜色没有改变)