为什么我的窗体不变颜色呀。
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();
}
}
运行后的结果窗体不显示红色也。和没有设置颜色一样。
----------------解决方案--------------------------------------------------------
你拖动你的窗体还是可以看到红色的
----------------解决方案--------------------------------------------------------
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();
}
}
----------------解决方案--------------------------------------------------------