2011-07-16 9 views
2

Frame()がsuper()の内部で使用されている間、初期化を行う方法はありますか?有効な方法で次のように、フレームとすべてのスーパー関連の色が赤色になるようにしますか?Frame()の内部構造をsuper()で行う方法は?

注:色(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); 
     ... 
    } 

} 
+0

999がクラスの有効な名前であるかどうかわかりません。私はJavaを知りません... –

+0

[クラス名](http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.1)は[idenitifier]( http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.8)、「999」は有効な名前ではありません。 – trashgod

+0

1)SwingとAWTを混在させないでください。 2)すぐにより良い助けを得るために、[SSCCE](http://pscode.org/sscce.html)を投稿してください。 –

答えて

3

このコードは本当に奇妙です。別の場所にフレームを作成し、このオブジェクトに渡す前に必要な値を設定します。または、コンストラクタでこの呼び出しを行います。

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

これはエラーを出しています:super(new Frame(){getOwner()。setBackground(new Color(255、0、0、255));}); – YumYumYum

+0

いいえ、999クラスのコンストラクタです。 – jzd

+0

上記を参照してください、その動作していない、私は透明の代わりに赤の背景があります。 – YumYumYum

関連する問題