📄 electiveui.java
字号:
/*
* ElectiveList.java
*
* Created on 2006年8月29日, 下午4:21
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package cn.edu.nwpu.MobileCampusClinet;
import cn.edu.nwpu.MobileCampusServer.ElectiveBean;
import java.util.Vector;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
/**
*
* @author NickJava
*/
public class ElectiveUI extends List implements CommandListener{
//可选修的选修课数组
private Vector electiveArray;
//用户选择的数组
private boolean[] selectedArray;
//用户选择的选修课名
private String[] hasChoice;
//查看选修课的详细信息的Form
private Form showElective;
//显示用户选择的选修课确认的Form
private Form ensureInfo;
//用户的ID
private String userName;
private Command seeCommand;
private Command OKCommand;
private Command backCommand;
private MIDlet midlet;
private Display display;
private Displayable displayable;
private GaugeObserverUI gaugeObserverUI;
/** Creates a new instance of ElectiveList */
public ElectiveUI(MIDlet midlet,Displayable displayable , Vector electiveArray , String userName){
super("选修课列表", Choice.MULTIPLE);
this.electiveArray=electiveArray;
selectedArray=new boolean[electiveArray.size()];
hasChoice=new String[5];
showElective = new Form("选修课信息");
ensureInfo = new Form("确认信息");
OKCommand = new Command("确定",Command.OK , 5);
backCommand = new Command("返回",Command.BACK,5);
seeCommand = new Command("查看",Command.BACK,5);
this.userName=userName;
this.midlet=midlet;
this.display=Display.getDisplay(midlet);
this.displayable=displayable;
gaugeObserverUI = new GaugeObserverUI();
appendElective();
addCommand(seeCommand);
addCommand(OKCommand);
setCommandListener(this);
}
//向屏幕添加选修课的名称
public void appendElective(){
for(int i=0 ; i<electiveArray.size();i++){
ElectiveBean electiveName = (ElectiveBean) electiveArray.elementAt(i);
append(electiveName.getElectiveName(),null);
}
}
public void gaugeRun(Thread thread , String title , boolean stop){
gaugeObserverUI.init(title,stop);
display.setCurrent(gaugeObserverUI);
thread.start();
}
//显示错误
private void showError(String message, Displayable d){
Alert alert=new Alert("Error");
alert.setType(AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
alert.setString(message);
display.setCurrent(alert,d);
}
//查看用户选择得选修课信息
public void getElectiveForm(){
//清屏
showElective.deleteAll();
this.getSelectedFlags(selectedArray);
for(int i=0 ; i<electiveArray.size() ; i++){
if(selectedArray[i]==true){
ElectiveBean elective=(ElectiveBean)electiveArray.elementAt(i);
showElective.append( new StringItem(elective.getElectiveName(), " \r\n总人数 :"+elective.getTotalNum()
+" \r\n当前人数 :"+elective.getCurrentNum()
+" \r\n上课地点 :"+elective.getPlace()
+" \r\n时间 :"+elective.getTime()
+" \r\n任课教师 :"+elective.getTeacher()));
}
}
showElective.addCommand(backCommand);
showElective.setCommandListener(this);
}
//让用户确认自己所选修的课程
public void getEnsureInfo(){
//清屏
ensureInfo.deleteAll();
this.getSelectedFlags(selectedArray);
//用户可选修的选修课的数量
int electiveNum=0;
ensureInfo.append("用户ID :"+userName+" \r\n以下是您所选课程的详细清单 :");
for(int i =0; i<electiveArray.size();i++){
if(selectedArray[i]==true){
ElectiveBean elective=(ElectiveBean)electiveArray.elementAt(i);
if(electiveNum<5){
hasChoice[electiveNum++]=elective.getElectiveName();
ensureInfo.append( new StringItem(elective.getElectiveName(), " \r\n总人数 :"+elective.getTotalNum()
+" \r\n当前人数 :"+elective.getCurrentNum()
+" \r\n上课地点 :"+elective.getPlace()
+" \r\n时间 :"+elective.getTime()
+" \r\n任课教师 :"+elective.getTeacher()));
}
}
ensureInfo.addCommand(OKCommand);
ensureInfo.addCommand(backCommand);
ensureInfo.setCommandListener(this);
}
}
//开辟一个线程用于网络连接,处理选修课,如果操作成功向resultForm中添加成功信息
public void addClass(final String username , final String[] electiveName){
Thread thread = new Thread(){
public void run(){
try{
HTTPConnection hc=new HTTPConnection(gaugeObserverUI);
ResultForm resultForm = new ResultForm(midlet,displayable,electiveArray,userName);
for(int i=0 ; i<electiveName.length ; i++){
if(electiveName[i]!=null){
if(hc.addElective(username , electiveName[i])==true){
resultForm.append("\r\n");
resultForm.append(electiveName[i]+":操作成功");
}else{
resultForm.append("\r\n");
resultForm.append("\r\n"+electiveName[i]+":操作失败");
}
}
}
display.setCurrent(resultForm);
if(gaugeObserverUI!=null){
gaugeObserverUI=null;
}
}catch(Exception e){
showError(e.getMessage(),ElectiveUI.this);
}
}
};
gaugeRun(thread,"正在进行数据同步",false);
}
//处理监听器
public void commandAction(Command c,Displayable d){
//当前屏幕
if(d.equals(this)){
if(c==seeCommand){
getElectiveForm();
display.setCurrent(showElective);
}
if(c==OKCommand){
getEnsureInfo();
display.setCurrent(ensureInfo);
}
}
//查看屏幕
if(d.equals(showElective)){
if(c==backCommand){
display.setCurrent(this);
}
}
//确认屏幕
if(d.equals(ensureInfo)){
if(c==backCommand){
display.setCurrent(this);
}
if(c==OKCommand){
addClass(userName , hasChoice);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -