今天只添加了一个药水图片,在添加药水的数量,打印文字时发现文字会和前面积分的文字重合,分别修改坐标发现两个修改坐标都不能使文字位置改变,目前还没有解决,今天太晚,明天再说。
public class Bg {
//总分
static int count=0;
static int waterNum=3;//药水数量
Image bg=Toolkit.getDefaultToolkit().getImage("imgs/bg.jpg");
Image bg1=Toolkit.getDefaultToolkit().getImage("imgs/bg1.jpg");
Image peo=Toolkit.getDefaultToolkit().getImage("imgs/peo.png");
Image water=Toolkit.getDefaultToolkit().getImage("imgs/water.png");
void paintSelf(Graphics g){
g.drawImage(bg,0,200,null);
g.drawImage(bg1,0,0,null);
g.drawImage(peo,310,50,null);
drawWord(g,30,Color.black,"积分:"+count,30,150);
g.drawImage(water,450,40,null);
drawWord(g,30,Color.black,"*"+waterNum,510,70);
}
//打印字符串
public static void drawWord(Graphics g,int size,Color color,String str,int x,int y){
g.setColor(color);
g.setFont(new Font("仿宋",Font.BOLD,size));
g.drawString(str,30,150);
}
}