学习总结9
1:今天做事件處理,發(fā)現(xiàn)在JMenu上面加監(jiān)聽,處理不行,只有在JMenuItem上面加監(jiān)聽處理才可以!!!就在這個簡單的問題上面糾纏了好長時間。還是得注意細(xì)細(xì)節(jié)啊!!!! (注:JMenu可以加監(jiān)聽,以前總結(jié)是有錯誤的!!)
?
2:給JFrame添加背景圖片:
ImageIcon img = new ImageIcon("XX.jpg");
JLabel imgLabel = new JLabel(img);
frame.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
imgLabel.setBounds(0,0,img.getIconWidth(), img.getIconHeight());((JPanel)getContentPane()).setOpaque(false);?
?
要在JFrame上添加背景圖片,常見做法是加在layeredPane上面,并將contentPane設(shè)置成透明的即可。
?
public void setBack() {
?? ((JPanel) this.getContentPane()).setOpaque(false);
?? // Winter.jpg這個圖片的位置要跟當(dāng)前這個類是同一個包下
?? URL url = Test.class.getResource("Winter.jpg");
?? ImageIcon img = new ImageIcon(url);
?? JLabel background = new JLabel(img);
?? this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
?? background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?這個封裝成方法寫的不錯,拷貝下來以后直接用!!!!
轉(zhuǎn)載于:https://www.cnblogs.com/cshhs/articles/3109339.html
總結(jié)
- 上一篇: java拾遗录(一)
- 下一篇: 数据连接java面试题