当前位置: 代码迷 >> Java相关 >> 为什么我的窗体不变颜色呀。
  详细解决方案

为什么我的窗体不变颜色呀。

热度:54   发布时间:2008-03-17 22:41:55.0
为什么我的窗体不变颜色呀。
import java.awt.Button;
import java.awt.Color;

import javax.swing.JFrame;
public class cca {
    JFrame f=new JFrame("hello");
    Button b=new Button("");
   
   public cca()
    {
       f.setSize(600,600);
       f.setBackground(Color.red);
       f.setVisible(true);
      
    }

    public static void main(String[] args) {
        
       cca aa=new cca();
    }
}
运行后的结果窗体不显示红色也。和没有设置颜色一样。
搜索更多相关的解决方案: 窗体  cca  import  awt  颜色  

----------------解决方案--------------------------------------------------------
你拖动你的窗体还是可以看到红色的
----------------解决方案--------------------------------------------------------
import java.awt.Button;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import javax.swing.JFrame;
public class cca extends JFrame implements ActionListener{
   
   
   public cca()
    {  super("hello");
       this.setSize(600,600);
      
       Button b=new Button("确定");
       b.setBackground(Color.red);
      

       Container cp=this.getContentPane();
       cp.setLayout(new BorderLayout());
       cp.setBackground(Color.red) ;   
       //cp.add(b);

     
       this.setVisible(true);
       b.addActionListener(this);
    }
    public void actionPerformed(ActionEvent e)
    {
        this.setForeground(Color.BLACK);
        }

    public static void main(String[] args) {
        
       cca aa=new cca();
      
    }
}
----------------解决方案--------------------------------------------------------
  相关解决方案