?? mainmidlet.java
字號:
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class MainMIDlet extends MIDlet implements CommandListener {
//private static MainMIDlet instance; //???為什么
//顯示管理器
Display display = null;
// 時鐘對象
static Ticker ticker = new Ticker("昆宇手機選課系統");
// 命令對象
static final Command exitCommand = new Command("退出", Command.EXIT, 2);
static final Command okCommand = new Command("確定", Command.OK, 0);
static final Command backCommand = new Command("返回", Command.BACK, 0);
//String currentMenu = null;
public static String serverip ="localhost:8080"; //可想法省去
public static String url = null;
//顯示對象
private LoginFrame loginframe = new LoginFrame(this);
private ChooseFrame chooseframe = new ChooseFrame(this);
private QueryFrame queryframe = new QueryFrame(this);
private ModifyFrame modifyframe = new ModifyFrame(this);
private QueryCourseTable querycoursetable=new QueryCourseTable(this);
private DisplayCourseTable displaycoursetabel=new DisplayCourseTable(this);
private NewsFrame newsframe=new NewsFrame(this);
public ImageScreen imagescreen = new ImageScreen(this);
public MyConnection myconnection = null;
//主菜單
private List menu = new List("選課系統", Choice.IMPLICIT);
public String username = null; //保存用戶名
public int choosed; //已選課程數
public int[] courseChoosedid = new int[5]; //儲存已選課程,最多選5門課
public String[] courseChoosed = null;
public int courseNum = 0;
public int[] allcourseid = null; //儲存所有課程
public String[] allcourse = null;
private Image img_choose = null;
private Image img_query = null;
private Image img_pass = null;
public void ShowMain() { //顯示主菜單
display.setCurrent(menu);
}
public void ShowLogin() {
display.setCurrent(loginframe.Show());
}
public void ShowChoose() {
display.setCurrent(chooseframe.Show());
}
public void ShowQuery() {
display.setCurrent(queryframe.Show());
}
public void ShowModify() {
display.setCurrent(modifyframe.Show());
}
public void ShowQueryCourseTable(){
display.setCurrent(querycoursetable.Show());
}
public void ShowDisplayCourseTabel(){
display.setCurrent(displaycoursetabel.Show());
}
public void ShowCategory(){
display.setCurrent(newsframe.ShowCategory());
}
public void ShowTitle(){
display.setCurrent(newsframe.ShowTitle());
}
public void ShowDetail(){
display.setCurrent(newsframe.ShowDetail());
}
// 構造器.
public MainMIDlet() {
try {
img_choose = Image.createImage("/res/choose.png");
img_query = Image.createImage("/res/query.png");
img_pass = Image.createImage("/res/pass.png");
} catch (IOException e) {
e.printStackTrace();
}
menu.append("選課", img_choose);
menu.append("查詢選課結果", img_query);
menu.append("修改密碼", img_pass);
menu.append("查詢課表",img_query);
menu.append("學院信息發布",img_query);
menu.addCommand(exitCommand);
menu.setCommandListener(this);
menu.setTicker(ticker);
}
public void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
ShowLogin(); //正式
//ShowMain(); //測試用
}
public void pauseApp() {
display = null;
ticker = null;
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void commandAction(Command c, Displayable d) {
String label = c.getLabel();
if (label.equals("退出")) {
destroyApp(true);
}
//List down = (List) display.getCurrent();
switch (menu.getSelectedIndex()) {
case 0:
//選課前讀取課程信息
if (this.courseNum == 0) {
//建立連接,讀取所有課程。
url = "http://" + MainMIDlet.serverip
//+ "/TestWebProject/ProcessAllcourse";
+ "/CourseSelect/ProcessAllcourse";
System.out.println(url);
//next:0-登錄 1-主菜單,2-選課,3-查詢,4-修改密碼界面
myconnection = new MyConnection(this, url, "讀取課程列表",2,1); //直接進入選課界面
myconnection.setGet();
myconnection.start();
} else {
display.setCurrent(chooseframe.Show());
}
break;
case 1:
url = "http://" + MainMIDlet.serverip
//+ "/TestWebProject/ProcessQuery?user=" + this.username;
+ "/CourseSelect/ProcessQuery?user=" + this.username;
System.out.println(url);
myconnection = new MyConnection(this, url, "查詢選課結果",3,1); //直接進入查詢結果界面
myconnection.setGet();
myconnection.start();
//display.setCurrent(queryframe.Show());
break;
case 2:
display.setCurrent(modifyframe.Show());
break;
case 3:
display.setCurrent(querycoursetable.Show());
break;
case 4:
display.setCurrent(newsframe.ShowCategory());
break;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -