JAVA,解释一下这些话每句话的意思.

问题描述:

JAVA,解释一下这些话每句话的意思.
((JPanel) this.getContentPane()).setOpaque(false);
ImageIcon JLabel background = new JLabel(img);
this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
1个回答 分类:综合 2014-09-17

问题解答:

我来补答
该类应该继承了JFrame 类
this.getContentPane(); 得到的是一个容器 (Container)对象
(JFrame)this.getContentPane() ; 将该容器 (Container) 强转为面板对象(JFrame)
((JPanel) this.getContentPane()).setOpaque(false); 将该面板设置为透明;
ImageIcon JLabel background = new JLabel(img); 创建一个标签,并将上面创建的图标对象给该标签,意思是该标签的背景就是 image文件夹下面 “对对碰1.jpg”这张图片了
this.getLayeredPane() 得到一个JLayeredPane 对象,这个类为容器添加了深度,允许组件在需要时互相重叠.
this.getLayeredPane().add(background,new Integer(Integer.MIN_VALUE)); 这句话的意思是,为前面创建的标签 设置层的深度,这里将其设置为了最底层,因为Integer.MIN_VALUE是int类型的最小值了
background.setBounds(0,0,img.getIconWidth(),img.getIconHeight()); 这里是调整label标签在容器的位置,并调整该标签的大小
这里有四个参数,前面两个是确定在容器中的位置的,后面两个是调整标签的大小的,这里它定义的是在容器的 左上角位置,标签的长 和宽 跟“对对碰1.jpg”这张图片的长和宽相等.
 
 
展开全文阅读
剩余:2000