⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 querycoursetable.java

📁 这是一个可以在手机客户端运行的选课系统 这个是服务器端
💻 JAVA
字号:

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.*;

/*
 * 创建日期 2005-3-25
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */

/**
 * @author huihui
 * 
 * TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */

public class QueryCourseTable implements CommandListener {
	MainMIDlet mainmidlet = null;

	private Form mainForm = new Form("选择班级");

	private String[] grade = { "01", "02", "03", "04", "05", "06", "07", "08" };

	private String[] classes = { "01", "02", "03", "04", "05", "06", "07",
			"08", "09", "10", "11" };

	private String classname = null;

	private String content = "";

	public static String[][] CourseTable = new String[7][5];

	ChoiceGroup[] groups = { new ChoiceGroup("年级", 4, grade, null),
			new ChoiceGroup("班级", 4, classes, null) };

	// create the list of choice groups.
	public QueryCourseTable(MainMIDlet mainmidlet) {
		this.mainmidlet = mainmidlet;

		for (int i = 0; i < groups.length; i++) {
			mainForm.append(groups[i]);
		}
		mainForm.addCommand(MainMIDlet.okCommand);
		mainForm.addCommand(MainMIDlet.backCommand);
		mainForm.setCommandListener(this);
	}

	public Displayable Show() {
		MainMIDlet.ticker.setString("昆宇系统--查询课表");
		mainForm.setTicker(MainMIDlet.ticker);
		mainForm.setCommandListener(this);
		return mainForm;
	}

	/*
	 * (非 Javadoc)
	 * 
	 * @see javax.microedition.lcdui.CommandListener#commandAction(javax.microedition.lcdui.Command,
	 *      javax.microedition.lcdui.Displayable)
	 */
	public void commandAction(Command c, Displayable d) {
		String label = c.getLabel();
		if (label.equals("返回")) {
			this.mainmidlet.ShowMain();
		} else if (label.equals("确定")) {

			for (int j = 0; j < groups[0].size(); j++) {
				if (groups[0].isSelected(j)) {
					classname = groups[0].getString(j);
					break;
				}
			}
			for (int j = 0; j < groups[1].size(); j++) {
				if (groups[1].isSelected(j)) {
					classname += groups[1].getString(j);					
					break;
				}
			}
			new Thread(new HttpConnector()).start();
			this.mainmidlet.imagescreen.show(3, "连接服务器……", 1); //3:load
		}
	}

	class HttpConnector implements java.lang.Runnable {
		//线程主方法
		public void run() {
			getTable();
		}
	}

	private void getTable() {
		try {
			MainMIDlet.url = "http://" + MainMIDlet.serverip
					+ "/CourseSelect/ProcessClassCourse?classname=" + classname;
			System.out.println(MainMIDlet.url);
			HttpConnection connection = (HttpConnection) Connector
					.open(MainMIDlet.url);
			InputStream is = null;
			is = connection.openInputStream();
			DataInputStream dis = new DataInputStream(is);
			int errorcode = dis.readInt();

			System.out.println(errorcode);
			if (errorcode == 1) {
				for (int i = 0; i < 7; i++) {
					//CourseTable[i]=new String[7];
					for (int j = 0; j < 5; j++) {
						CourseTable[i][j] = dis.readUTF();
					}
				}
				/*
				 for (int j = 0; j < 5; j++) {					
				 CourseTable[0][j] = dis.readUTF();
				 }
				 */
				dis.close();
				is.close();
				connection.close();
				this.mainmidlet.ShowDisplayCourseTabel();
			} else {
				switch (errorcode) { //判断错误代码
				case -3:
					content = "与数据库连接错误";
					break;
				case -6:
					content = "没有该班级";
					break;
				default:
					//System.out.println(content);
					content = "连接服务器失败";
					break;
				}
				this.mainmidlet.imagescreen.show(2, content, 5);//5 选择班级
			}
		} catch (IOException ex) {
			ex.printStackTrace();
			this.mainmidlet.imagescreen.show(2, "连接服务器失败", 1);
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -