mainmidlet.java

来自「这是一个可以在手机客户端运行的选课系统 这个是服务器端」· Java 代码 · 共 185 行

JAVA
185
字号

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 + =
减小字号Ctrl + -
显示快捷键?