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

📄 searchform.java

📁 手机在线系统 采用Java 中的J2ME, JSP 跟MySql 运行环境是:jsdk1.4以上
💻 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.phonebook;

import com.j2me.main.*;	
import com.j2me.language.*;
import javax.microedition.lcdui.*;

/**
 *此类为搜索类
 */
public class  SearchForm extends Form implements CommandListener 
{
	private Display display = null;
	private PhoneBookMenu phoneBookMenu = 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, PhoneBookMenu phoneBookMenu, int type)
	{
		this.display = display;
	   	this.phoneBookMenu = phoneBookMenu;
		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(phoneBookMenu);
		}

		if (c == okCommand)
		{
			Friend friend = null;
			PhoneBook pb = new PhoneBook();
			if (searchType == 1)
			{
				friend = pb.getFriend(searchTextField.getString());	 //通过名得到朋友的信息
			}
			else
			{
				friend = pb.getFriend(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.phoneItem.setLabel("Phone:");
				this.detailInfoForm.eMailItem.setLabel("Email:");
				
			}
			else  //修改语言属性为中文										
			{
				this.detailInfoForm = new DetailInfoForm("详细信息");
				this.detailInfoForm.idItem.setLabel("ID:");
				this.detailInfoForm.nameItem.setLabel("姓名:");
				this.detailInfoForm.phoneItem.setLabel("电话:");
				this.detailInfoForm.eMailItem.setLabel("邮箱:");
			}

			if (friend.getID()<10)
			{
				this.detailInfoForm.showForm(display, phoneBookMenu, "00" + friend.getID() + friend.getName());

			}
			else if (friend.getID()<100)
			{
				this.detailInfoForm.showForm(display, phoneBookMenu, "0" + friend.getID() + friend.getName());
			}
			else
			{
				this.detailInfoForm.showForm(display, phoneBookMenu, friend.getID() + friend.getName());
			}

			if (friend.getID() == 0)	//如果没搜索到显示错误
			{
			  this.display.setCurrent(errorAlert, phoneBookMenu);
			}
			
		}
	}
}

		



⌨️ 快捷键说明

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