怎么用setBackground(Color)没起作用,没颜色变化
import javax.swing.*;
import java.awt.*;
public class Chuangkou {
public static void main(String[] args)
{
JFrame jf=new JFrame("按钮对象的创建");
JButton btn1=new JButton("按钮一");
JButton btn2=new JButton("");
btn2.setText("按钮二");
Container cp=jf.getContentPane();
jf.setForeground(Color.yellow);
jf.setBackground(Color.red);
cp.setLayout(null);
jf.setSize(400,250);
jf.setLocation(400,250);
cp.add(btn1);
cp.add(btn2);
btn1.setBounds(60,20,80,30);
btn2.setBounds(60,60,80,30);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}
}