public class text2 extends Frame{
Image img = GameUtil.getImage("images/fly.jpg");
public void launchFrame(){
setSize(500,300);
setLocation(0,0);
setVisible(true);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}//点关闭可以关闭窗口
});
}
public void paint(Graphics g){
Color c = g.getColor();
g.setColor(Color.blue);
g.drawOval(100, 100, 100, 100);
g.drawImage(img, 200, 200, null);
}
public static void main(String args[]){
text2 t1 = new text2();
t1.launchFrame();
}
}
报错跳转为
public static BufferedImage read(URL input) throws IOException {
if (input == null) {
throw new IllegalArgumentException("input == null!");
}
setVisible(true);放在main方法里面
你自己跟踪调试下哪一块代码报错啊,你的代码不全没有GameUtil类的信息,没办法测试。
package text;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.net.URL;
import java.io.IOException;
import javax.imageio.ImageIO;
//工具类
public class GameUtil {
public static Image getImage(String path){
URL u =GameUtil.class.getClassLoader().getResource(path);
BufferedImage img =null;
try{
img = ImageIO.read(u);
}catch(IOException e){
e.printStackTrace();
}
return img;
}
}