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

📄 searchenglishform.java

📁 手机在线系统 采用Java 中的J2ME, JSP 跟MySql 运行环境是:jsdk1.4以上
💻 JAVA
字号:
/**
 * @(#)SearchEnglishForm.java	1.11 01/08/23
 * Copyright (c) 2004-2005 wuhua of workroom Inc. All Rights Reserved.
 * @version 	1.0, 10/05/2004
 * @author 	饶荣庆
 * @author 	余煜辉
 */
package com.j2me.dictionary;

import com.j2me.language.*;
import com.j2me.main.*;
import com.j2me.common.*;
import java.io.*;
import javax.microedition.lcdui.*;

/**
 *此类是用英语查找单词的显示层
 */
public class SearchEnglishForm extends Form implements CommandListener, ItemStateListener
{
	private Display display;
	private DictionaryMenu dictionary;

	/*数据输入对象*/
	public TextField key; //输入查找关键字;
	public StringItem result; //返回查找结果

	/*定义ChoiceGroup对象数组用来给用户筛选*/
	public ChoiceGroup choice;

	/*声音线程*/
	private PronunciationThread pT;

	/*错误*/
	private Alert errorAlert = null;

	//定义离开软键
	private Command backCommand = null;		
	private Command okCommand = null;
	private Command playCommand = null;
	private Command stopCommand = null;
    
	/*用于判断是否精确查找*/
	private String isExactitude = "true";
	private String[] data = new String[2];
	private String uRL;
	private	String par;

	/*-----------------------------------------------------------------------
	 *构造方法
	 */
	public SearchEnglishForm(String title)
	{
		super(title);
		this.key = new TextField("输入单词:", "", 100, TextField.ANY);
		this.result = new StringItem("结果:  ", "");
		this.choice = new ChoiceGroup("筛选", Choice.EXCLUSIVE);
		this.choice.append("精确查找", null);
		this.choice.append("模糊查找", null);
		this.backCommand = new Command("返回", Command.BACK, 2);	
		this.okCommand = new Command("确定", Command.BACK, 2);	
		this.playCommand = new Command("播放", Command.OK, 2);
		this.stopCommand = new Command("停止", Command.OK, 2);
		this.addCommand(backCommand);
		this.addCommand(okCommand);
		this.append(key);
		this.append(choice);
		this.append(result);
		this.setCommandListener(this);
		this.setItemStateListener(this);
	}

	/*显示菜单界面方法*/
	public void showForm(Display display, DictionaryMenu dictionary)	//用来显示界面
	{		
		this.display = display;
	   	this.dictionary = dictionary;
		this.display.setCurrent(this);
	} 


	/**
	 *定义私有方法下载数据
	 */
	private void callHttp(String URLString, String parameter)
	{		
		uRL = URLString;
		par = parameter;

		Thread t = new Thread() 
		{   
			public void run() 
			{ 
				String html= "";
				try
				{	
					//获得服务器用户保存的内容
					html = ConnectHttp.invokeJSP(uRL, par);
				
     				//处理HTML标记语言
			    	html = DisposeHTML.getBody(html.trim());	
			    	data = DisposeData.getStringGroup(html, "~", 2);
					System.out.println(html);
					System.out.println(data[1]);

			    }
			    catch(IOException e)
				{
					errorAlert  = new Alert("ERROR", "对不起!连接错误", null, AlertType.ERROR);	
					errorAlert.setTimeout(2000);
					display.setCurrent(errorAlert);
					result.setText("");
				}
				if (html.trim().compareTo("false") == 0)
				{
					errorAlert  = new Alert("ERROR", "对不起!找不到这个单词!", null, AlertType.ERROR);
					errorAlert.setTimeout(2000);
					display.setCurrent(errorAlert);
					result.setText("");
				}
				else
				{
					if (isExactitude.compareTo("true") == 0)
					{
						addCommand(playCommand);
					}
					else
					{
						removeCommand(playCommand);
					}
                    //this.addCommand(stopCommand);

					if (isExactitude.compareTo("true") == 0)
					{
						result.setText("\n" + data[0]);
						System.out.println(data[1]);
						
					}
					else
					{
						result.setText(html);
					}
					
				}
			}
		};

	   t.start();	  //启动线程让它进行连网	
	}


	public void commandAction(Command c,Displayable s)
	{
		if (c == backCommand)
		{
			this.display.setCurrent(dictionary);
			try
			{
				this.pT.close();
			}
			catch(NullPointerException n)
			{
			}
		}
		if (c == okCommand)
		{
			//参数
			String parameter =  "key=" + key.getString().trim() + "&filter=" + isExactitude;
			if (key.getString().trim().compareTo("") != 0)
			{
				this.result.setText("\n连接网络...");
				this.callHttp(DictionaryServerURL.getURL() + "english_find.jsp", parameter);
			}
			else
			{
				errorAlert  = new Alert("ERROR", "对不起!请输入单词", null, AlertType.ERROR);	
         		errorAlert.setTimeout(2000);
		        this.display.setCurrent(errorAlert);
			}
		}
		if (c == playCommand)
		{
			pT = new PronunciationThread(DictionaryServerURL.getURL() +"pronunciation/" + data[1] + ".mid");
			pT.start();
			//this.append("从服务器上下载声音!请稍等...");
			this.addCommand(stopCommand);
			this.removeCommand(playCommand);
		}
		if (c == stopCommand)
		{	
			this.pT.stop();
			this.addCommand(playCommand);
			this.removeCommand(stopCommand);
		}
		
	}

    /**
	 *判断用户是否是精确查找的事件
	 */
	public void itemStateChanged(Item item)
	{
		if (item == choice)
		{
			/*判断用户是否精确查找*/
			if (choice.isSelected(0))
			{
				isExactitude = "true";  //设置查找参数为精确查找
				System.out.println(isExactitude);
			}
			if (choice.isSelected(1))
			{
				isExactitude = "false";
				
			}
			
		}
	}


}

⌨️ 快捷键说明

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