?? main.java
字號(hào):
package main;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class Main extends Canvas implements Runnable {
public Image img_logo1, img_logo2, img_logo3, img_logo4, img_logo5,
img_about, img_bg;
public static int stateloadingX = 0; // 進(jìn)度條的X坐標(biāo)
public Image img_menu = null;
public static int logo_time = 500; // 1000為一秒
private final static int stateloading = 1; // 進(jìn)度條
private final static int stateMenu = 2; // 菜單
private final static int stateAbout = 3; // 關(guān)于
private final static int stateHelp = 4; // 幫助
private final static int stateStudent = 5; // 學(xué)生號(hào)碼
private static int currentState = 0; // 當(dāng)前狀態(tài)
private final static int sonyWidth = 176; // sonyEricsson-K550屏幕寬
private final static int sonyHeight = 220; // sonyEricsson-K550屏幕高
private static String[] strMenu = { "學(xué)生號(hào)碼", "臨時(shí)鎖定", "日程安排", "鎖定解鎖 ",
"在線升級(jí) ", "幫助", "關(guān)于" };
private static int selectedRow = 0; // 當(dāng)前選中的行
private static int selectedRowX = 20;
public static String mobile="";
Midlet midlet = null;
Command cmdBack = null;
public Main(MIDlet m) {
try {
// this.setFullScreenMode(true);
midlet = (Midlet) m;
img_logo1 = Image.createImage("/logo1.png");
img_logo2 = Image.createImage("/logo2.png");
img_logo3 = Image.createImage("/logo3.png");
img_logo4 = Image.createImage("/logo4.png");
img_logo5 = Image.createImage("/logo5.png");
img_bg = Image.createImage("/imagebg2.png");
Thread thread = new Thread(this);
thread.start();
currentState = stateloading; // 一開始就讀取進(jìn)度條
Display.getDisplay(m).setCurrent(this);
} catch (Exception e) {
e.printStackTrace();
}
}
protected void paint(Graphics g) {
try {
// 進(jìn)度條
if (currentState == stateloading) {
// 清屏
g.setColor(255, 255, 255);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
//畫圖片
if (logo_time == 500)
g.drawImage(img_logo1, 0, 0, 0);
if (logo_time == 1000)
g.drawImage(img_logo2, 0, 0, 0);
if (logo_time == 1500)
g.drawImage(img_logo3, 0, 0, 0);
if (logo_time == 2000)
g.drawImage(img_logo4, 0, 0, 0);
if (logo_time == 2500)
g.drawImage(img_logo5, 0, 0, 0);
//畫進(jìn)度條邊框
g.setColor(0, 0, 0);
g.drawRect((this.getWidth() - 150) / 2, 195, 150, 10);
//畫進(jìn)度條的實(shí)心條
g.setColor(0, 255, 0);
g.fillRect((this.getWidth() - 150) / 2, 195, stateloadingX * 15,
10);
//寫進(jìn)度條的百分比
g.setColor(0, 0, 0);
g.drawString(String.valueOf(stateloadingX * 10) + "%", 75, 192,
0);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
// 菜單
if (currentState == stateMenu) {
// 清屏
g.setColor(255, 255, 255);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
//背景圖片
g.drawImage(img_bg, 0, 0, 0);
//寫字(菜單)
for (int i = 0; i < strMenu.length; i++) {
if (i == selectedRow) {
g.setColor(246, 247, 171);
g.fillRect((this.getWidth() - 80) / 2, (i + 1) * 25, 80,
20);
g.setColor(255, 0, 0);
g.drawString(strMenu[i], this.getWidth() / 2,
(i + 1) * 25, Graphics.HCENTER | Graphics.TOP);
} else {
g.setColor(0, 0, 0);
g.drawString(strMenu[i], this.getWidth() / 2,
(i + 1) * 25, Graphics.HCENTER | Graphics.TOP);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
try {
// 關(guān)于
if (currentState == stateAbout) {
g.setColor(255, 255, 255);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.drawImage(img_about, 0, 0, 0);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
// 幫助
if (currentState == stateHelp) {
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void run() {
while (true) {
// 關(guān)于
try {
if (currentState == stateAbout) {
repaint();
continue;
}
} catch (Exception e) {
e.printStackTrace();
}
// 幫助
try {
if (currentState == stateHelp) {
repaint();
continue;
}
} catch (Exception e) {
e.printStackTrace();
}
// 進(jìn)度條和圖片變量
try {
if (currentState == stateloading) {
logo_time = logo_time + 500;
stateloadingX = stateloadingX + 1;
if(stateloadingX==1)
{
mobile=RMS.load();
System.out.println("load:"+mobile);
}
// System.out.println(logo_time);
if (stateloadingX > 10) {
// stateloadingX = 10;
currentState = stateMenu;
}
if (logo_time > 2500) {
logo_time = 2500;
}
}
} catch (Exception e) {
e.printStackTrace();
}
repaint();
try {
Thread.sleep(200);
} catch (Exception e) {
e.printStackTrace();
}
}
}
protected void keyPressed(int keyCode) {
// 進(jìn)度條
if (currentState == stateloading) {
return;
}
// 菜單
try {
if (currentState == stateMenu) {
// 向下
if (keyCode == -2 || keyCode == 56) {
selectedRow = selectedRow + 1;
if (selectedRow > strMenu.length - 1) {
selectedRow = 0;
}
}
// 向上
if (keyCode == -1 || keyCode == 50) {
selectedRow = selectedRow - 1;
if (selectedRow < 0) {
selectedRow = strMenu.length - 1;
}
}
// 選中
if (keyCode == -5) {
if(selectedRow==0)
{
SetMobileForm setMobileForm=new SetMobileForm(midlet,this);
}
if (selectedRow == 6) {
img_about = Image.createImage("/imgabout.png");
currentState = stateAbout;
}
}
// 退出
if (keyCode == -7) {
midlet.destroyApp(false);
midlet.notifyDestroyed();
}
}
} catch (Exception e) {
e.printStackTrace();
}
// 關(guān)于
try {
if (currentState == stateAbout) {
if (keyCode == -7) {
currentState = stateMenu;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -