如何用super()做Frame()的内部构造?

时间:2011-07-16 12:48:13

标签: java linux swing user-interface awt

如果在super()中使用它,我怎么能对Frame()进行初始化?喜欢以有效的方式跟随,以便Frame和所有超级相关的颜色都是RED?

注意:基本上不应该显示正确的红色框,因为颜色(r,g,b,ALPHA);

enter image description here

public class 999 extends Window 
{
  private JLabel label;
  private JButton button;
  private static final Canvas canvas = new Canvas();
  private static final Canvas canvas0 = new Canvas();
  private JLayeredPane layers;

  public 999() 
  {
        super(new Frame());
        // Please make this **TRANSPARENT**
        getOwner().setBackground( new Color(255, 0, 0, 0) ); 

        layers = new JLayeredPane();
        button = new JButton("close");

        this.setLayout (new BorderLayout ());     

        button.setBackground(Color.RED);
        button.setSize(200,200);
        button.setLocation(0,20);
        this.add("North", button);

        JPanel p = new JPanel();
        p.setOpaque(false); // transparent
        p.setBackground( new Color(255, 0, 0, 0) ); // transparent

        p.setSize(300, 200);
        p.setLocation(0, 0);
        p.add(new JButton("Test"));
        layers.add(p, new Integer(1));
        layers.setSize(400,300);
        layers.setLocation(400,50);

        layers.setOpaque(false); // transparent
        layers.setBackground( new Color(255, 0, 0, 0) ); // transparent
        this.add("North", layers);

        canvas.setSize(800,800);
        this.add("North",canvas);
        //AWTUtilities.setWindowOpacity(this, 0.2f); // Error in Linux

    }

    public static void main(String[] args) 
    {
      Window j = new 999();
      j.setVisible(true);
        ...
    }

}

1 个答案:

答案 0 :(得分:3)

这段代码很奇怪。在其他位置创建框架并在将其提供给此对象之前设置所需的值。或者只是在构造函数中进行此调用:

 getOwner().setBackground( new Color(255, 0, 0, 255) );