当前位置: 代码迷 >> J2SE >> java awt怎么添加背景图片
  详细解决方案

java awt怎么添加背景图片

热度:61   发布时间:2016-04-24 00:57:34.0
java awt如何添加背景图片
RT,用awt添加一个Frame,再在它上面加一张背景图片。
注:不能用swing


------解决方案--------------------
Java code
import java.awt.Frame;import java.awt.Graphics;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.image.BufferedImage;import java.io.File;import javax.imageio.ImageIO;public class BGTest extends Frame{    private BufferedImage bgImage;    public BGTest() throws Exception{        this.setTitle("bg");        this.setSize(400, 600);        this.addWindowListener(new WindowAdapter(){            @Override            public void windowClosing(WindowEvent e) {                System.exit(0);            }        });                bgImage = ImageIO.read(new File("c:/psb.jpg"));    }        @Override    public void paint(Graphics g) {        g.drawImage(bgImage, 0, 0, this.getWidth(), this.getHeight(), this);    }        public static void main(String[] args) {        try {            new BGTest().setVisible(true);        } catch (Exception e) {            e.printStackTrace();        }    }}
------解决方案--------------------
+1
探讨
Java code

import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;

……
  相关解决方案