jframe怎么不能显示背景颜色
import java.awt.*;
import javax.swing.*;class Test_animate{
public static void main(String[] arg){
Animate gui=new Animate();
gui.go();
}

public void go(){
JFrame fr=new JFrame();
fr.setSize(200,200);
fr.setBackground(Color.red);
fr.setVisible(true);
}

}初学,请帮一下,谢谢了

解决方案 »

  1.   

    public class NewJFrame { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO 自动生成方法存根
    JFrame fr=new JFrame();
    fr.setSize(200,200);
    fr.getContentPane().setBackground(Color.red);
    fr.setVisible(true);
    }}给你改了一下,关键的就是这句:fr.getContentPane().setBackground(Color.red);
      

  2.   

    jPanel1.setBackground(Color.yellow);
    this.getContentPane().add(jPanel1,  BorderLayout.CENTER);