RookieApe
2014-03-29 10:07
采纳率: 100%
浏览 5.1k
已采纳

java 关于添加图片到窗体背景

代码如下
Game.java

import javax.swing.JFrame;
public class Game{

public static void main(String[] args){ 
    JFrame window = new JFrame();
    window.setSize(800,600);
    window.setLocation(270,100);
    window.setTitle("我的图片");
    window.show();
}

}

MyJFrame.java
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.JFrame;

public class MyJFrame extends Game{

Image mapImage;
Image lxyImage;

public MyJFrame(){

    try{
        File file = new File("D:/素材/地图/0.png");
        mapImage = ImageIO.read(file);
        lxyImage = ImageIO.read(new File("D:/素材/图片/0.png"));
    }catch(Exception e){
        e.printStackTrace();
    }
}
public void paint(Graphics g){
    g.drawImage(mapImage, 0, 0, null);
    g.drawImage(lxyImage, 400, 300, null);
}

}
求解答,新人,尽量详细点,不胜感激!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • shiter 2015-01-19 13:49
    已采纳

    这个是解决方案:

     http://maicle.iteye.com/blog/512664
    
    点赞 打赏 评论

相关推荐 更多相似问题