drawImage()函数为什么显示不了图片
图片资源放在了src文件中了,同时我又复制一份到新建了的包images中了,图像加载成功了,我用了toString方法对Image类定义的数组进行序列化输出有值sun.a...
图片资源放在了src文件中了,同时我又复制一份到新建了的包images中了, 图像加载成功了,我用了toString方法对Image类定义的数组进行序列化输出有值sun.awt.image.ToolkitImage@3d494fbf sun.awt.image.ToolkitImage@1ddc4ec2 sun.awt.image.ToolkitImage@133314b sun.awt.image.ToolkitImage@b1bc7ed sun.awt.image.ToolkitImage@7cd84586 sun.awt.image.ToolkitImage@30dae81 sun.awt.image.ToolkitImage@1b2c6ec2 sun.awt.image.ToolkitImage@4edde6e5 sun.awt.image.ToolkitImage@70177ecd sun.awt.image.ToolkitImage@1e80bfe8 sun.awt.image.ToolkitImage@66a29884 sun.awt.image.ToolkitImage@4769b07b sun.awt.image.ToolkitImage@cc34f4d //用来加载要显示的图片public void getPic() { pic = new Image[14]; for(int i = 0; i < 13; i++) { pic[i] = Toolkit.getDefaultToolkit().getImage("images\\pic"+i+".jpg"); System.out.println( pic[i].toString() ); } } //paint(Graphics g)方法绘制整个游戏区域的图形。public void paint(Graphics g)//绘图{ // g.drawImage(pic[0],0,0,this); g.drawImage(pic[1], 140, 140, this); for(int i = 0; i < mapRow; i++) for(int j = 0; j < mapColumn; j++) {//画出地图,i表示行数,j表示列数if(map[i][j] != 0) { g.drawImage(pic[map[i][j]],leftX + j*40, leftY + i*40,this); System.out.println(pic[map[i][j]].toString()); } } g.setColor(Color.RED); g.setFont(new Font("楷体_2312",Font.BOLD,30)); g.drawString("现在是第",150,140); g.drawString(String.valueOf(grade+1),310,140); g.drawString("关", 360, 140); }
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询