2 u012378692 u012378692 于 2014.03.29 18:07 提问

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个回答

wangyaninglm
wangyaninglm   Ds   Rxr 2015.01.19 21:49
已采纳

这个是解决方案:

 http://maicle.iteye.com/blog/512664
Csdn user default icon
上传中...
上传图片
插入图片