java窗口如何添加背景图片,并且大小和窗口适应
1、final ImageIcon bgImageIcon = new ImageIcon(MyJFrame.class.getClassLoader().getResource("com/zjc/Desert.jpg"));
final Image image = bgImageIcon.getImage();
//设置背景图片的路径地址

2、JFrame frame = new JFrame("this is background pic test") {
private static final long serialVersionUID = 1L;
public void paint(Graphics g) {
g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), null);
}
};
//进行图重绘

3、frame.setSize(300, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
//设置frame对象显示出来

4、运行后效果如下图:

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
                                阅读量:20
阅读量:38
阅读量:75
阅读量:145
阅读量:108