📄 musicitem.java
字号:
package unicoco;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.CustomItem;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
public class MusicItem extends CustomItem implements Runnable {
String[] strings;
byte selection;
boolean condi;
Font font;
int curIndex;
boolean isFocus;
public MusicItem() {
super("Music");
strings = new String[] { "close", "open" };
condi = true;
font = Font.getFont(Font.FONT_STATIC_TEXT);
}
public void run() {
while (condi) {
int target = selection * 10;
if (curIndex != target) {
curIndex = (curIndex + 1) % (strings.length * 10);
repaint();
}
try {
Thread.sleep(50);
} catch (Exception e) {
}
}
}
protected int getMinContentHeight() {
return font.getHeight();
}
protected int getMinContentWidth() {
int max = 0;
for (int i = 0; i < strings.length; i++) {
String v = strings[i];
int width = font.stringWidth(v);
max = Math.max(max, width);
}
int width = font.stringWidth(getLabel() + 10);
max = Math.max(max, width);
return max;
}
protected int getPrefContentHeight(int arg0) {
return font.getHeight();
}
protected int getPrefContentWidth(int arg0) {
return getMinContentWidth();
}
protected void paint(Graphics g, int w, int h) {
int fraction = curIndex % 10;
int realIndex = (curIndex - fraction) / 10;
String v = strings[realIndex];
g.setFont(font);
int bc = MIDGame.display.getColor(Display.COLOR_BACKGROUND);
int fc = MIDGame.display.getColor(Display.COLOR_FOREGROUND);
g.setColor(bc);
g.fillRect(0, 0, w, h);
g.setColor(fc);
if (fraction == 0) {
g.drawString(v, 0, 0, Graphics.TOP | Graphics.LEFT);
return;
}
int lineHeight = font.getHeight();
int divider = lineHeight - lineHeight * fraction / 10;
g.drawString(v, 0, divider - lineHeight, Graphics.TOP | Graphics.LEFT);
realIndex = (realIndex + 1) % strings.length;
v = strings[realIndex];
g.setStrokeStyle(Graphics.DOTTED);
g.drawLine(0, divider, w, divider);
g.drawString(v, 0, divider, Graphics.TOP | Graphics.LEFT);
}
boolean changed = false;
protected void keyPressed(int arg0) {
if (getGameAction(arg0) == Canvas.FIRE) {
if (!changed) {
changed = true;
}
selection = (byte) ((selection + 1) % strings.length);
}
}
protected boolean traverse(int arg0, int arg1, int arg2, int[] arg3) {
isFocus = true;
repaint();
return false;
}
protected void traverseOut() {
isFocus = false;
repaint();
}
protected void showNotify() {
selection = MIDGame.game.music;
condi = true;
Thread t = new Thread(this);
t.start();
}
protected void hideNotify() {
condi = false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -