import java.awt.*;
import javax.swing.*;public class Test {
public static void main(String args[]) {
JFrame f = new JFrame("My Test");
Container ct = new Container();
JButton bn = new JButton("BN");
JButton bs = new JButton("BS");
JButton bw = new JButton("BW");
JButton be = new JButton("BE");
JButton bc = new JButton("BC");

ct.add(bn, "North");
ct.add(bs, "South");
ct.add(bw, "West");
ct.add(be, "East");
ct.add(bc, "Center"); f.setBackground(Color.BLACK);
f.setLocation(400,200); 
f.setSize(400,400);
f.setVisible(true);
}
}为什么加不上按钮呢?
还有背景颜色为什么不是黑色的?
谢谢

解决方案 »

  1.   

    你的按钮是加到Container ct中去了,可是Container ct 并没有加到JFrame f中去啊
      

  2.   

    你的背景只是 Content 的背景, 但是你可能只看到了 Button 。其它的都没有看见。
      

  3.   

    因为JFrame有Container,背景被Container遮住了,如设置背景可以设置Container的背景,
    ct.setBackground(Color.BLACK);
      

  4.   

    请问怎么改变按钮的颜色 还有按钮上面的字符的颜色bn.setForeground(Color.red);