手机在线系统
采用Java 中的J2ME, JSP 跟MySql
运行环境是:jsdk1.4以上
源代码在线查看: searchform.java
/**
* @(#)SearchForm.java
* Copyright (c) 2004-2005 wuhua of workroom Inc. All Rights Reserved.
* @version 1.0, 10/05/2004
* @author 饶荣庆
* @author 余煜辉
*/
package com.j2me.myphoto;
import com.j2me.main.*;
import com.j2me.language.*;
import javax.microedition.lcdui.*;
/**
*此类为搜索类
*/
public class SearchForm extends Form implements CommandListener
{
private Display display = null;
private PhotoBookMenu photoBookMenu = null;
private PhotoList photoList = null;
public static Alert errorAlert = null; //找不到记录是显示错误信息
public static TextField searchTextField= null;
public Command okCommand = null; //定义确定软键
public Command backCommand = null; //定义离开软键
public DetailInfoForm detailInfoForm = null;
private int searchType;
public SearchForm(String s)
{
super(s);
this.errorAlert = new Alert("错误", "找不到这条记录", null, AlertType.ERROR); //初始化信息
this.errorAlert.setTimeout(1000);
this.searchTextField = new TextField(null, null, 30, TextField.ANY);
this.okCommand = new Command("确定", Command.OK, 2);
this.backCommand = new Command("返回", Command.BACK, 2);
this.addCommand(backCommand);
this.addCommand(okCommand);
this.setCommandListener(this);
}
public void showForm(Display display, PhotoBookMenu photoBookMenu, PhotoList photoList, int type)
{
this.display = display;
this.photoBookMenu = photoBookMenu;
this.photoList = photoList;
this.searchType = type;
if (type == 1) //判断用户用那种类型进行搜索并作出响应
{
this.searchTextField.setMaxSize(30); //设置最大可以容下30字
this.searchTextField.setConstraints(TextField.ANY);
}
else
{
this.searchTextField.setMaxSize(3);
this.searchTextField.setConstraints(TextField.NUMERIC);
}
this.append(searchTextField);
this.display.setCurrent(this);
}
public void commandAction(Command c,Displayable s)
{
if(c == backCommand)
{
this.display.setCurrent(photoBookMenu);
}
if (c == okCommand)
{
Photo photo = null;
PhotoBook pb = new PhotoBook();
if (searchType == 1)
{
photo = pb.getPhoto(searchTextField.getString()); //通过名得到朋友的信息
}
else
{
photo = pb.getPhoto(Integer.parseInt(searchTextField.getString())); //通过id得到朋友的信息
}
if (Language.isEnglish == true) //修改语言为英文
{
this.detailInfoForm = new DetailInfoForm("Detail Info"); //new一个详细信息对象
this.detailInfoForm.idItem.setLabel("ID:");
this.detailInfoForm.nameItem.setLabel("Name:");
this.detailInfoForm.pathItem.setLabel("Path:");
}
else //修改语言属性为中文
{
this.detailInfoForm = new DetailInfoForm("详细信息");
this.detailInfoForm.idItem.setLabel("ID:");
this.detailInfoForm.nameItem.setLabel("图片名:");
this.detailInfoForm.pathItem.setLabel("路径:");
}
if (photo.getID() {
this.detailInfoForm.showForm(display, photoList, photoBookMenu, null, "00" + photo.getID());
}
else if (photo.getID() {
this.detailInfoForm.showForm(display, photoList, photoBookMenu,null, "0" + photo.getID());
}
else
{
this.detailInfoForm.showForm(display, photoList, photoBookMenu, null, photo.getID() + "");
}
if (photo.getID() == 0) //如果没搜索到显示错误
{
this.display.setCurrent(errorAlert, photoBookMenu);
}
}
}
}