📄 jmp.java
字号:
//import com.nttdocomo.ui.*;
import javax.microedition.lcdui.*;
import com.lm.nttdocomo.ui.Display;
import com.lm.nttdocomo.ui.IApplication;
import com.massp.util.SettingsTracking;
import com.massp.util.StringResourceReader;
import com.vodafone.v10.system.device.DeviceControl;
/**
* The main entry into the application.
*
* @author <a href="mailto:xp@livingmobile.net">Xavier Palau</a>
* @version $Revision: 1.8.4.13 $
* @changed $Author: xavier $ $Date: 2004/02/19 11:33:19 $
*/
public class JMP extends IApplication implements Runnable, CommandListener {
private JMPS canv;
private String locale;
public static StringResourceReader txt;
private List menu;
private String nick;
public DeviceControl device;
private SettingsTracking tracker;
public boolean sound = true;
public boolean vibra = true;
private boolean light = true;
static final int CMD_OK = Command.BACK;
static final int CMD_BACK = Command.OK;
public void start()
{
txt = new StringResourceReader();
try {
locale = System.getProperty("microedition.locale");
locale = (locale != null && locale.length() >= 2 ? locale.substring(0, 2).toLowerCase() : "en");
if (!txt.load(this, "/text__" + locale + ".bin")) {
locale = "en";
txt.load(this, "/text.bin");
}
} catch (Exception e) {}
System.gc();
canv = new JMPS();
System.gc();
device = DeviceControl.getDefaultDeviceControl();
tracker = new SettingsTracking(this, new int[] { 0, 1, 2 });
sound = (tracker.getSetting(0, (byte) 1) == 0 ? false : true);
vibra = (tracker.getSetting(1, (byte) 1) == 0 ? false : true);
light = (tracker.getSetting(2, (byte) 1) == 0 ? false : true);
if (light) device.setDeviceActive(DeviceControl.BACK_LIGHT, true);
String[] content = txt.getBundle("frmMenu");
menu = new List(content[0], List.IMPLICIT);
try {
for (int i = 1; i < content.length; i++)
menu.append(content[i], Image.createImage("/images/icon_" + i + ".png"));
} catch (Exception e) { }
menu.addCommand(new Command(txt.getBundle("cmdBack")[0], CMD_BACK, 1));
menu.addCommand(new Command(txt.getBundle("cmdOK")[0], CMD_OK, 1));
menu.setCommandListener(this);
Display.setCurrent(canv);
canv.initAll();
Thread runner = new Thread(this);
runner.start();
}
public void notifyGameOver() {
menu.setSelectedIndex(1, true);
commandAction(List.SELECT_COMMAND, menu);
}
public void notifyMenu() {
Display.setCurrent(menu);
}
public void resume() {
//canv.Resume();
}
public void run() {
int K = 0;
long lt = System.currentTimeMillis();
int c = 0;
for(;;) {
try {
if (canv.isPaused) {
Thread.sleep(50);
continue;
}
K |= canv.getKeypadState();
c = (int)( System.currentTimeMillis() - lt ) / 100;
if (c > 0 ) {
canv.ProEvent(K);
lt += c * 100; //System.currentTimeMillis();
K = 0;
}
}
catch (Exception e) {}
}
}
public void commandAction(Command c, Displayable d) {
String lbl = c.getLabel();
if (c == List.SELECT_COMMAND
|| (lbl.equals(txt.getBundle("cmdOK")[0]) && d == menu)) {
int index = menu.getSelectedIndex();
Form f = null;
String[] content = null;
switch (index) {
case 0:
Display.setCurrent(canv);
canv.startTutorial();
break;
case 1:
Display.setCurrent(canv);
canv.startScores();
break;
case 2:
content = txt.getBundle("frmOptions");
List l = new List(content[0], List.MULTIPLE);
for (int i = 1; i < content.length; i++) l.append(content[i], null);
l.setSelectedFlags(new boolean[] {sound, vibra, light} );
l.addCommand(new Command(txt.getBundle("cmdBack")[0], CMD_BACK, 1));
l.setCommandListener(this);
Display.setCurrent(l);
break;
case 3:
content = txt.getBundle("frmInstructions");
f = new Form(content[0]);
f.append( lineBreak(content[1], 23) );
f.addCommand(new Command(txt.getBundle("cmdBack")[0], CMD_BACK, 1));
f.setCommandListener(this);
Display.setCurrent(f);
break;
case 4:
content = txt.getBundle("frmAbout", new String[] { "app.locale" },
new String[] { locale });
f = new Form(content[0]);
for (int i = 1; i < content.length; i++) {
f.append(content[i] + "\n");
}
f.addCommand(new Command(txt.getBundle("cmdBack")[0], CMD_BACK, 1));
f.setCommandListener(this);
Display.setCurrent(f);
break;
}
} else if (lbl.equals(txt.getBundle("cmdBack")[0])) {
if (d == menu) {
canv.notifyTitle();
Display.setCurrent(canv);
} else {
if (d instanceof List) {
List l = (List) d;
boolean[] flags = new boolean[3];
l.getSelectedFlags(flags);
sound = flags[0];
vibra = flags[1];
light = flags[2];
if (light) device.setDeviceActive(DeviceControl.BACK_LIGHT, true);
else device.setDeviceActive(DeviceControl.BACK_LIGHT, false);
tracker.setSetting(0, (byte) (sound ? 1 : 0));
tracker.setSetting(1, (byte) (vibra ? 1 : 0));
tracker.setSetting(2, (byte) (light ? 1 : 0));
}
Display.setCurrent(menu);
}
} else if (lbl.equals(txt.getBundle("cmdExit")[0])) destroyApp(true);
}
public String lineBreak(String source, int linelength)
{
int length = source.length();
StringBuffer result = new StringBuffer(length + 20);
int pos=0;
int lineindex;
int nextspace = 0;
while (pos < length) {
lineindex = pos;
// append words until line break
nextspace = source.indexOf(" ", pos);
while (true) {
result.append(source.substring(pos, nextspace));
pos = nextspace + 1;
nextspace = source.indexOf(" ", pos);
if (nextspace == -1) {
// last words/line
if (length >= lineindex + linelength) result.append('\n');
else result.append(' ');
result.append(source.substring(pos, length));
pos = length;
break;
}
else if (nextspace < lineindex + linelength) result.append(' ');
else break;
}
result.append('\n');
}
return result.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -