如何使用 super() 进行 Frame() 的内部构造?

发布于 2024-11-24 18:51:10 字数 1647 浏览 0 评论 0原文

当 Frame() 在 super() 内部使用时,如何对其进行初始化?就像以有效的方式遵循以下一样,以便框架和所有超级相关的颜色都为红色?

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

在此处输入图像描述

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);
        ...
    }

}

How can i do a initialization for the Frame() while its getting used inside the super()? Like following in a valid way, so that the Frame and all super related has a color RED?

Note: Basically the right red box should not show because Color(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);
        ...
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心意如水 2024-12-01 18:51:10

这段代码确实很奇怪。在其他地方创建框架并设置所需的值,然后再将其赋予该对象。或者只是在构造函数中进行此调用:

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

This code is really odd. Create the frame elsewhere and set the values you want before you give it to this object. Or just make this call in your constructor:

 getOwner().setBackground( new Color(255, 0, 0, 255) );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文