?? querycoursetable.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 + -