【Java开源代码栏目提醒】:网学会员Java开源代码为您提供Bonus.java参考,解决您在Bonus.java学习中工作中的难题,参考学习。
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class Bonus
{
public static Graphics g = null;
private Image bonus;
private Image imgTimer;
private Image imgPower;
private Image imgBomber;
private Image imgWall;
private Image imgTanker;
private Image imgCap;
private Image imgBlock;
public int bonusKind;
public int bonusX;
public int bonusY;
public int formerBonusX;
public int formerBonusY;
public int bonusWidth;
public int bonusHeight;
int count = 1;
public Bonus()
{
bonusKind = 0;
bonusX = - 1;
bonusY = - 1;
formerBonusX = - 1;
formerBonusY = - 1;
try
{
bonus = Image.createImage("/bonus.png");
bonusWidth = bonus.getWidth() / 3;
bonusHeight = bonus.getHeight() / 2;
imgBomber = Image.createImage(bonusWidth, bonusHeight);
g = imgBomber.getGraphics();
g.drawImage(bonus, 0, 0, g.TOP | g.LEFT);
imgPower = Image.createImage(bonusWidth, bonusHeight);
g = imgPower.getGraphics();
g.drawImage(bonus, - bonusWidth, 0, g.TOP | g.LEFT);
imgTanker = Image.createImage(bonusWidth, bonusHeight);
g = imgTanker.getGraphics();
g.drawImage(bonus, - bonusWidth * 2, 0, g.TOP | g.LEFT);
imgTimer = Image.createImage(bonusWidth, bonusHeight);
g = imgTimer.getGraphics();
g.drawImage(bonus, 0, - bonusHeight, g.TOP | g.LEFT);
imgWall = Image.createImage(bonusWidth, bonusHeight);
g = imgWall.getGraphics();
g.drawImage(bonus, - bonusWidth, - bonusHeight, g.TOP | g.LEFT);
imgCap = Image.createImage(bonusWidth, bonusHeight);
g = imgCap.getGraphics();
g.drawImage(bonus, - bonusWidth * 2, - bonusHeight, g.TOP | g.LEFT); //g.TOP|g.LEFT:g.topleft
imgBlock = Image.createImage("/back.png");
}
catch (Exception exception)
{
System.out.println(exception);
}
}
synchronized void paint(Graphics g)
{
if (count % 3 != 0)
{
switch (bonusKind)
{
case 1:
g.drawImage(imgTimer, bonusX, bonusY, g.TOP | g.LEFT);
break;
case 2:
g.drawImage(imgPower, bonusX, bonusY, g.TOP | g.LEFT);
break;
case 3:
g.drawImage(imgBomber, bonusX, bonusY, g.TOP | g.LEFT);
break;
case 4:
g.drawImage(imgWall, bonusX, bonusY, g.TOP | g.LEFT);
break;
case 5:
g.drawImage(imgTanker, bonusX, bonusY, g.TOP | g.LEFT);
break;
case 6:
g.drawImage(imgCap, bonusX, bonusY, g.TOP | g.LEFT);
break;
default:
break;
}
}
else
{
g.drawImage(imgBlock, bonusX, bonusY, g.TOP | g.LEFT);
count = 0;
}
count++;
}
}