package system.dept;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Vector;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.*;
import com.jufeng.MidpTable;
/**
* 部门报表的显示
* @author FOX
*
*/
public class ShowForm implements CommandListener{
private Display display ;//MIDLET显示对象传进来,便于返回
private List parentList ;//父界面也要传递进来便于返回上一个界面
private Form showForm = null;
/**确认删除Form*/
private Form SureDelForm;
/**删除Form中的确定提交删除命令*/
private Command cmdisDel;
/**删除的后退命令*/
Command cmdBack;
private Command cmdExitDept ;
/**主Form中的添加命令*/
private Command cmdAddDept;
/**主Form中的删除命令*/
private Command cmdDelDept;
/**主Form中的修改命令*/
private Command cmdModDept;
/**主Form中的查询命令*/
private Command cmdFindDept;
/** 表格控件 */
private static MidpTable table = null;
String defaultURL = "http://127.0.0.1:8088/ServerProiims/servlet/ServletShowDept";
/**
* 构造方法,必须加PUBLIC,否则只在包内可见
* @param cmd
* ,把要监听对象传递进来
*/
public ShowForm(Display display,List parentList){//把显示对象和从哪个界面过来(即父界面)的那个界面传进来,方便返回父界面
this.display = display;//把外面的显示对象传递进来
this.parentList = parentList;//把父界面也传进来
showForm = new Form("部门信息维护");//CUSTOM不能直接显示
//mainForm.append("测试");
cmdExitDept = new Command ("返回",Command.EXIT,2);
cmdAddDept = new Command("添加",Command.SCREEN,1);
cmdDelDept = new Command ("删除",Command.SCREEN,1);
cmdModDept = new Command ("修改",Command.SCREEN,1);
cmdFindDept = new Command ("查询",Command.SCREEN,1);
showForm.addCommand(cmdExitDept);
showForm.addCommand(cmdAddDept);
showForm.addCommand(cmdDelDept);
showForm.addCommand(cmdModDept);
showForm.addCommand(cmdFindDept);
showForm.setCommandListener(this);
/**开销时间大的操作,新开一个线程来做*/
new Thread(){
public void run(){
showAllInvokeServlet(defaultURL);
}}.start();
}
public void setShowForm(Form showForm) {
this.showForm = showForm;
}
/**得到ShowForm类对象*/
public Form getShowForm() {
return showForm;
}
/*****************get和set方法结束*************************/
/**调用显示全部记录的方法*/
public void showAllInvokeServlet(String url){
HttpConnection hc = null;
DataOutputStream dos = null;
DataInputStream dis = null;
try{
hc = (HttpConnection)Connector.open(url,Connector.READ_WRITE); //设置请求属性
hc.setRequestMethod(HttpConnection.POST); //设置为POST请求方式,默认的请求方式是GET
hc.setRequestProperty("Connection","Keep-Alive");
dos = hc.openDataOutputStream(); //写到输出流中去,以便服务器端从里面取数据
dos.writeUTF("SHOW");
dos.flush();
dos.close();
//接收servlet响应数据
dis = new DataInputStream(hc.openInputStream()); //用于接受服务器端放在流中的东西,这个过程很象SOCKET程序
/*把所有内容显示在表格里面*/
/*把数据库中所有数据显示在手机主界面上*/
Vector ptitle = new Vector();//表头标题
ptitle.addElement("部门编号"); ptitle.addElement("部门名称"); ptitle.addElement("负责人");
Vector pweiba = new Vector();//表尾
pweiba.addElement(" "); pweiba.addElement(" "); pweiba.addElement(" ");
Vector pdata= new Vector();
system.dept.ClientUtil cUtil = new system.dept.ClientUtil();//建立工具类对象
pdata = cUtil.distreamToVector(dis);
pdata.addElement(pweiba);
table = new MidpTable("部门信息",ptitle,pdata);
table.setLayout(Item.LAYOUT_CENTER);
table.setDx(73);//设置一下单元格长度
showForm.append(table);
//display.setCurrent(mainForm);
}
catch(IOException e){System.out.print("showAllInvokeServlet(String url)错误"+e);}
finally{
try{
if (dis != null) {dis.close();}
if (dos != null) {dos.close();}
if (hc != null) {hc.close();}
}catch(IOException e){System.out.print("showAllInvokeServlet(String url)错误"+e);}
}
//display.setCurrent(returnForm); //设置当前窗口
}
public void sureDelForm(){
SureDelForm = new Form("");
cmdisDel = new Command ("是",Command.SCREEN,1);
cmdBack = new Command ("否",Command.BACK,1);
SureDelForm.addCommand(cmdisDel);
SureDelForm.addCommand(cmdBack);
SureDelForm.setCommandListener(this);
SureDelForm.append("如果选择删除,该记录将从数据库中消失,下次将无法找到!你确定要删除吗?");
}
public void commandAction(Command c, Displayable d) {
if (c == cmdExitDept) {//返回上一个父界面
display.setCurrent(parentList);//对象是引用传递,所以执行的是其对象本身
}
if (c == cmdAddDept) {//返回上一个父界面
AddForm addForm = new AddForm(display,showForm,table);
display.setCurrent(addForm.getAddForm());//对象是引用传递,所以执行的是其对象本身
}
if (c == cmdModDept) {//返回上一个父界面
ModForm modForm = new ModForm(display,showForm,table);
display.setCurrent(modForm.getModForm());//对象是引用传递,所以执行的是其对象本身
}
if(c == cmdDelDept){
sureDelForm();
display.setCurrent(SureDelForm);
}
if (c == cmdisDel){
new Thread(){
public void run(){
System.out.println("删除数据"+table.getSelectRow());
table.delRow(table.getSelectRow());
}
}.start();
display.setCurrent(showForm);
}
if(c == cmdBack){
display.setCurrent(showForm);
}
}
}
Example_server_client.rar_ExampleServer类
版权申诉
4 浏览量
2022-09-22
16:53:38
上传
评论
收藏 4KB RAR 举报
林当时
- 粉丝: 100
- 资源: 1万+
最新资源
- 开源代码分享(31)-计及电转气协同的含碳捕集与垃圾焚烧虚拟电厂优化调度
- meta-llama-3-8b-instruct 的 model-00002-of-00004.safetensors 的1/3
- AnyTXT.Searcher.1.3.1168.Win32&Win64.exe
- Redis windows版本的redis安装包和可视化工具客户端、redis存取数据的项目demo
- code1_2
- L999_期末项目.ipynb
- 数字频率计的设计(内含原理图、源代码、实物照片)
- 国密SM4加解密,前后端文件合集
- 基于TypeScript和UmiJS的高校学生报名系统设计源码 - student-sign
- 免费gpt4系列、claude-3、gemini 等模型傻瓜式开箱即用
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈