?? searchform.java
字號:
/* * SearchForm.java * * Created on 2004年1月13日, 下午7:03 */package handenglish;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import java.util.*;/** * * @author Administrator * @version */public class SearchForm extends Form implements ReceiveListener,CommandListener,Runnable{ private Receive m_Receive; private Midlet midlet; private TextField m_Input; private Command m_CmdSearch; private StringItem m_Result; private Vector m_Words; private boolean doSearch = false; private Thread searchThread; public SearchForm(Midlet midlet) { super( "單詞查詢" ); this.midlet = midlet; m_Receive = new Receive(midlet); m_Receive.setReceiveListener( this ); m_Input = new TextField( "輸入查詢單詞","",60,TextField.ANY ); m_CmdSearch = new Command( "查詢",Command.OK,0 ); m_Words = new Vector(); m_Result = new StringItem( "","" ); append( m_Input ); addCommand( m_CmdSearch ); addCommand( midlet.cmdBack ); setCommandListener( this ); startThread(); } public void dataReceived(int cmd, int status) { m_Result.setLabel( "查詢結果" ); StringBuffer strs = new StringBuffer(); for( int i = 0;i< m_Words.size();i++ ) { strs.append( m_Words.elementAt(i) ); strs.append( "\n\n" ); } if ( m_Words.size() == 0 ) m_Result.setText( "您查的單詞未找到!" ); else m_Result.setText( strs.toString() ); } public void dataReceiving(int cmd, int pos, int total, int send) { } public void errorReceived(int errno) { Alert alert = new Alert( "錯誤信息","通訊錯誤,請與服務提供商聯系!錯誤號=" + errno ,null,AlertType.ERROR ); alert.setTimeout( Alert.FOREVER ); Display.getDisplay( midlet ).setCurrent( alert ); } public void setCurState(int curState) { } public void startThread() { if(searchThread==null) searchThread=new Thread(this); searchThread.start(); } public void stopThread() { searchThread = null; } public void commandAction(Command c, Displayable s) { if ( c == midlet.cmdBack && s == this ) { stopThread(); midlet.nowDisplay( s,midlet.WIN_MENU ); } else if( c == m_CmdSearch && s == this ) { if ( m_Input.getString().equals( null ) || m_Input.getString().equals( "" ) ) { Alert alert = new Alert( "警告信息","請輸入查詢單詞!" ,null,AlertType.WARNING ); alert.setTimeout( Alert.FOREVER ); Display.getDisplay( midlet ).setCurrent( alert ); return; } removeResult(); m_Result.setLabel( "正在查詢中,請稍候..." ); m_Result.setText(""); append( m_Result ); doSearch = true; } } private void removeResult() { for( int i=0;i< size();i++ ) { Item item = get( i ); if ( item == m_Result ) delete( i ); } } public void run() { Thread curThread = Thread.currentThread(); while ( searchThread == curThread ) { try { Thread.sleep( 200 ); if ( doSearch ) { m_Receive.queryWord( m_Input.getString(),m_Words ); doSearch = false; } }catch(Exception e){ //System.out.println(e.toString()); } } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -