自定义Jframe类,创建两个Jbutton按钮对象和内容面板。
frm.getContentPane().setBackground(Color.red)
this.getParent().setBackground(Color.red);
忘记很多了,效果不是很理想哈!
import javax.swing.*;
import java.awt.*;
public class Test1 {
public static void main(String[] args) {
JFrame frame = new JFrame("自定义窗口");
frame.setSize(400,350);
JPanel panel_1 = new JPanel();
panel_1.add(new JButton("Green"));
panel_1.add(new JButton("Red"));
panel_1.setSize(400,150);
JPanel panel_2 = new JPanel();
panel_2.setBackground(Color.red);
panel_2.setSize(400,200);
frame.add(panel_1);
frame.add(panel_2);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
运行结果: