日期:2014-05-20 浏览次数:20647 次
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