📄 ball.java
字号:
import java.io.IOException;
import javax.microedition.lcdui.*;
//定义出小球(7色球).BALL_NUM=7
public class Ball {
int id;
private int ball_DIMSzie=Cfg.BALL_DIM;
private Image ballImg;
public Image[] imgs = new Image[Cfg.BALL_NUM];
public int getBall_DIMSzie() {
return ball_DIMSzie;
}
public void setBall_DIMSzie(int ball_DIMSzie) {
this.ball_DIMSzie = ball_DIMSzie;
}
public Ball() {
for (int bId = 0; bId < imgs.length; ++bId) {
try {
ballImg = Image.createImage("/"+Cfg.BALL_COLORS_NAME[bId]);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (ball_DIMSzie==Cfg.Ball_REAL_SIZE) {
imgs[bId]=ballImg;
} else {
imgs[bId]=ImageUtil.scale(ballImg,ball_DIMSzie,ball_DIMSzie);
}
/*
Graphics g = imgs[bId].getGraphics();
g.setColor(Cfg.BGCOLOR);
g.fillRect(0, 0, ball_DIMSzie, ball_DIMSzie);
//g.setColor(Cfg.FGCOLOR);
//通过画直线,把球划出来的
//应该取出图片,或通过画圆的方式fillArc
g.setColor(Cfg.BALL_COLORS[bId]);
g.fillArc(0, 0, ball_DIMSzie, ball_DIMSzie, 0, 360);
//for (int line = 0; line < Cfg.BALL_PIXEL.length; ++line) {
// int startP = (Cfg.BALL_DIM - Cfg.BALL_PIXEL[line]) / 2;
// g.setColor(Cfg.BALL_COLORS[bId]);
// g.drawLine(startP, line, startP + Cfg.BALL_PIXEL[line] - 1,
// line);
//}
//System.out.println("ini_ball_DIMSzie="+ball_DIMSzie);
* */
}
}
public Ball(int c,int ball_DIMSzie) {
this.ball_DIMSzie = ball_DIMSzie;
id = c;
if (imgs[id]==null ) {
try {
ballImg = Image.createImage("/"+Cfg.BALL_COLORS_NAME[c]);
if (ball_DIMSzie==Cfg.Ball_REAL_SIZE) {
imgs[c]=ballImg;
} else {
imgs[c]=ImageUtil.scale(ballImg,ball_DIMSzie,ball_DIMSzie);
}
} catch (IOException e) {
// TODO Auto-generated catch block
imgs[c] = Image.createImage(ball_DIMSzie, ball_DIMSzie);
Graphics g = imgs[c].getGraphics();
g.setColor(Cfg.BGCOLOR);
g.fillRect(0, 0, ball_DIMSzie , ball_DIMSzie );
//g.setColor(Cfg.FGCOLOR);
//通过画直线,把球划出来的
//应该取出图片,或通过画圆的方式fillArc
g.setColor(Cfg.BALL_COLORS[c]);
g.fillArc(0, 0, ball_DIMSzie - 1, ball_DIMSzie - 1, 0, 360);
//System.out.println("ball_DIMSzie="+ball_DIMSzie);
}
}
}
/*
public void draw(Graphics g, int xPos, int yPos) {
int interval = Cfg.EDGE * 2 + ball_DIMSzie+ 1;
int x0 = Cfg.X0 + interval * xPos + 1 + Cfg.EDGE;
int y0 = Cfg.Y0 + interval * yPos + 1 + Cfg.EDGE;
g.drawImage(imgs[id], x0, y0, Graphics.LEFT | Graphics.TOP);
}
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -