加载图片问题
package cn.laowang.test;import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.imageio.ImageIO;
public class GameFrame extends Frame {
Image img=GameUtil.getImage("images/IZTT_3PX[ICU2[Y]M%CW`OF.jpg");
public void launchFrame(){
setSize(500,500);//设置大小
setLocation(100,100);//设置位置
setVisible(true);
/*
* 关闭窗口
*/
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
g.drawLine(100, 100, 200, 200);//画斜线
g.drawRect(100, 100, 200, 200);//画正方体
g.drawOval(100, 100, 200, 200);//画圆
Font f=new Font("宋体",Font.BOLD,100);//改变字体
g.setFont(f);
g.drawString("张龙这是我游戏开发的第一步",200, 200);
Color c=g.getColor();//得到一个旧的颜色
g.fillRect(100, 100, 100, 100);//填充颜色
g.setColor(Color.BLUE);
g.setColor(c);
g.drawImage(img, 200, 200, null);
}
public static void main(String[] args){
GameFrame gf =new GameFrame();
gf.launchFrame();
}
}
语法没问题,但是运行不出来
后面显示的错误是
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(ImageIO.java:1362)
at cn.laowang.test.GameUtil.getImage(GameUtil.java:23)
at cn.laowang.test.GameFrame.<init>(GameFrame.java:14)
at cn.laowang.test.GameFrame.main(GameFrame.java:56)