如何使用 super() 进行 Frame() 的内部构造?
当 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);
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这段代码确实很奇怪。在其他地方创建框架并设置所需的值,然后再将其赋予该对象。或者只是在构造函数中进行此调用:
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: