<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    小方的Java博客

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      27 隨筆 :: 17 文章 :: 115 評(píng)論 :: 0 Trackbacks
    GWT QQ 群號(hào):28310588

    功能:
    1。當(dāng)加載頁面時(shí)把數(shù)據(jù)庫的表讀入matchArr
    2。每次按鍵都是matchArr的查詢,查詢方法用正則表達(dá)式

    抱歉,沒什么注釋,給大家添麻煩了
    有任何疑問請(qǐng)聯(lián)系我
    qq:259102567?
    MSN:jorwen_fang@hotmail.com

    代碼下載

    我不久前寫的關(guān)于gwt文章

    另外在 《ajax in action》書中有提到更佳的算法,提高性能,以及打字過快的處理等功能。
    本人這個(gè)程序?qū)Ω?00以下數(shù)據(jù)還是可以忍受等待時(shí)間的




    代碼:
    1.InputHint.java
    package?mypack.client;

    import?java.util.ArrayList;

    import?com.google.gwt.core.client.EntryPoint;
    import?com.google.gwt.user.client.Window;
    import?com.google.gwt.user.client.rpc.AsyncCallback;
    import?com.google.gwt.user.client.ui.*;

    /**
    ?*?Entry?point?classes?define?<code>onModuleLoad()</code>.
    ?
    */

    public?class?InputHint?implements?EntryPoint?{

    ????
    private?ArrayList?matchArr;

    ????
    private?TextBox?tb;
    ????
    ????
    private?Label?label;

    ????
    private?ListBox?list;

    ????
    public?void?onModuleLoad()?{
    ????????label?
    =?new?Label("輸入:");
    ????????tb?
    =?new?TextBox();
    ????????IH_Service.Util.getInstance().getResult(
    ????????????
    new?AsyncCallback()?{
    ????????????????
    public?void?onSuccess(Object?result)?{
    ????????????????????matchArr?
    =?(ArrayList)?result;
    ????????????????}


    ????????????????
    public?void?onFailure(Throwable?caught)?{
    ????????????????????Window.alert(caught.toString());
    ????????????????}

    ????????????}

    ????????);
    ????????tb.addKeyboardListener(
    new?KeyboardListener()?{
    ????????????
    public?void?onKeyDown(Widget?sender,?char?keyCode,?int?modifiers)?{
    ????????????}


    ????????????
    public?void?onKeyPress(Widget?sender,?char?keyCode,?int?modifiers)?{
    ????????????????
    //?TODO?Auto-generated?method?stub

    ????????????}


    ????????????
    public?void?onKeyUp(Widget?sender,?char?keyCode,?int?modifiers)?{
    ????????????????fillList(tb.getText());
    ????????????}

    ????????}
    );
    ????????tb.addFocusListener(
    new?FocusListener()?{

    ????????????
    public?void?onFocus(Widget?sender)?{
    ????????????????list.clear();
    ????????????????
    if(tb.getText().equals("")){
    ????????????????????
    for?(int?i?=?0;?i?<?matchArr.size();?i++)?{
    ????????????????????????list.addItem((String)?matchArr.get(i));
    ????????????????????????list.setVisible(
    true);
    ????????????????????}

    ????????????????}
    else{
    ????????????????????fillList(tb.getText());
    ????????????????????list.setVisible(
    true);
    ????????????????}

    ????????????}


    ????????????
    public?void?onLostFocus(Widget?sender)?{
    ????????????????list.setVisible(
    false);

    ????????????}

    ????????}
    );
    ????????list?
    =?new?ListBox();
    ????????list.addChangeListener(
    new?ChangeListener()?{

    ????????????
    public?void?onChange(Widget?sender)?{
    ????????????????tb.setText(list.getItemText(list.getSelectedIndex()).trim());
    ????????????}

    ????????}
    );
    ????????list.setVisible(
    false);
    ????????list.setVisibleItemCount(
    10);
    ????????RootPanel.get(
    "label").add(label);
    ????????RootPanel.get(
    "tb").add(tb);
    ????????RootPanel.get(
    "list").add(list);
    ????}


    ????
    private?void?fillList(String?info)?{
    ????????IH_Service.Util.getInstance().fillList(info,?matchArr,
    ????????????????
    new?AsyncCallback()?{
    ????????????????????
    public?void?onSuccess(Object?result)?{
    ????????????????????????ArrayList?arr?
    =?(ArrayList)?result;
    ????????????????????????list.clear();
    ????????????????????????
    if(arr?==?null?||?arr.size()?==?0){
    ????????????????????????????list.addItem(
    "??????無匹配字符?");
    ????????????????????????????list.setVisible(
    true);
    ????????????????????????}
    else{
    ????????????????????????????
    for?(int?i?=?0;?i?<?arr.size();?i++)?{
    ????????????????????????????????list.addItem((String)?arr.get(i));
    ????????????????????????????????list.setVisible(
    true);
    ????????????????????????????}

    ????????????????????????}

    ????????????????????}


    ????????????????????
    public?void?onFailure(Throwable?caught)?{
    ????????????????????????Window.alert(caught.toString());
    ????????????????????}

    ????????????????}

    ????????);
    ????}

    }

    2.IH_Service.java
    package?mypack.client;

    import?java.util.ArrayList;

    import?com.google.gwt.core.client.GWT;
    import?com.google.gwt.user.client.rpc.RemoteService;
    import?com.google.gwt.user.client.rpc.ServiceDefTarget;

    public?interface?IH_Service?extends?RemoteService?{

    ????
    public?static?final?String?ENTRY_POINT="/IH_PRO/input_hint";

    ????
    public?static?class?Util{
    ????
    ??????
    public?static?IH_ServiceAsync?getInstance(){

    ????????????IH_ServiceAsync?instance?
    =?(IH_ServiceAsync)GWT.create(IH_Service.class);
    ????????????ServiceDefTarget?target?
    =?(ServiceDefTarget)instance;
    ????????????target.setServiceEntryPoint(ENTRY_POINT);
    ????????????
    return?instance;
    ??????}

    ????}

    ????
    ????
    public?ArrayList?getResult();
    ????
    public?ArrayList?fillList(String?info,?ArrayList?matchArr);
    }


    3.IH_ServiceAsync.java
    package?mypack.client;

    import?java.util.ArrayList;

    import?com.google.gwt.user.client.rpc.AsyncCallback;

    public?interface?IH_ServiceAsync?{

    ??????
    public?void?getResult(AsyncCallback?callback);
    ????
    public?void?fillList(String?info,?ArrayList?matchArr,?AsyncCallback?callback);
    }


    4.IH_ServiceImpl.java
    package?mypack.server;

    import?java.sql.*;
    import?java.util.ArrayList;
    import?java.util.regex.Matcher;
    import?java.util.regex.Pattern;

    import?mypack.client.IH_Service;
    import?com.google.gwt.user.server.rpc.RemoteServiceServlet;

    public?class?IH_ServiceImpl?extends?RemoteServiceServlet?implements?IH_Service?{
    ????
    private?static?final?long?serialVersionUID?=?1L;
    ????Connection?connection?
    =?null;
    ????PreparedStatement?pstm?
    =?null;
    ????ResultSet?rs?
    =?null;
    ????
    public?ArrayList?getResult(){
    ????????
    try?{
    ????????????Class.forName(
    "com.microsoft.jdbc.sqlserver.SQLServerDriver");
    ????????????connection?
    =?DriverManager
    ????????????????????.getConnection(
    ????????????????????????????
    "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ajax",
    ????????????????????????????
    "sa",?"sa");
    ????????????pstm?
    =?connection
    ????????????????????.prepareStatement(
    "select?name?from?T_INPUT");
    ????????????rs?
    =?pstm.executeQuery();
    ????????????ArrayList?arr?
    =?new?ArrayList();
    ????????????
    while(rs.next()){
    ????????????????arr.add(rs.getString(
    "name"));
    ????????????}

    ????????????
    return?arr;
    ????????}
    ?catch?(ClassNotFoundException?e)?{
    ????????????e.printStackTrace();
    ????????}
    ?catch?(Exception?e)?{
    ????????????e.printStackTrace();
    ????????}
    finally{
    ????????????
    try?{
    ????????????????
    if(rs?!=?null)
    ????????????????????rs.close();
    ????????????????
    if(pstm?!=?null)
    ????????????????????pstm.close();
    ????????????????
    if(connection?!=?null)
    ????????????????????connection.close();
    ????????????}
    ?catch?(SQLException?e)?{}
    ????????}

    ????????
    return?null;
    ????}

    ????
    ????
    public?ArrayList?fillList(String?info,?ArrayList?matchArr){
    ????????Pattern?p?
    =?Pattern.compile("^"+info+".");
    ????????Matcher?m
    =null;
    ????????ArrayList?arr?
    =?new?ArrayList();
    ????????
    for(int?i?=?0;?i?<?matchArr.size();?i++){
    ????????????m?
    =?p.matcher((String)matchArr.get(i));
    ????????????
    if(m.find()){
    ????????????????arr.add((String)matchArr.get(i));
    ????????????}

    ????????}

    ????????
    return?arr;
    ????}

    }


    5.mycss.css
    .sd{
    width
    :150px;
    background-color
    :cccccc;
    border
    :1px?solid?red;
    padding-left
    :2px;
    overflow
    :visible;
    }

    6.InputHint.html
    <!--<!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN"?"http://www.w3.org/TR/html4/loose.dtd">-->

    <html>
    ????
    <head>
    ????
    <meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8">
    ????
    ????????
    <!--???????????????????????????????????????????-->
    ????????
    <!--?Any?title?is?fine?????????????????????????-->
    ????????
    <!--???????????????????????????????????????????-->
    ????????
    <title>Wrapper?HTML?for?InputHint</title>

    ????????
    <!--???????????????????????????????????????????-->
    ????????
    <!--?Use?normal?html,?such?as?style????????????-->
    ????????
    <!--???????????????????????????????????????????-->
    ????????
    <style>
    ????????????body,td,a,div,.p
    {font-family:arial,sans-serif}
    ????????????div,td
    {color:#000000}
    ????????????a:link,.w,.w?a:link
    {color:#0000cc}
    ????????????a:visited
    {color:#551a8b}
    ????????????a:active
    {color:#ff0000}
    ????????
    </style>

    ????????
    <!--???????????????????????????????????????????-->
    ????????
    <!--?The?module?reference?below?is?the?link????-->
    ????????
    <!--?between?html?and?your?Web?Toolkit?module??-->????????
    ????????
    <!--???????????????????????????????????????????-->
    ????????
    <meta?name='gwt:module'?content='mypack.InputHint'>
    ????????
    <link?rel='stylesheet'?type='text/css'?href='mycss.css'/>
    ????????
    ????
    </head>

    ????
    <!--???????????????????????????????????????????-->
    ????
    <!--?The?body?can?have?arbitrary?html,?or??????-->
    ????
    <!--?you?can?leave?the?body?empty?if?you?want??-->
    ????
    <!--?to?create?a?completely?dynamic?ui?????????-->
    ????
    <!--???????????????????????????????????????????-->
    ????
    <body>

    ????????
    <!--????????????????????????????????????????????-->
    ????????
    <!--?This?script?is?required?bootstrap?stuff.???-->
    ????????
    <!--?You?can?put?it?in?the?HEAD,?but?startup????-->
    ????????
    <!--?is?slightly?faster?if?you?include?it?here.?-->
    ????????
    <!--????????????????????????????????????????????-->
    ????????
    <script?language="javascript"?src="gwt.js"></script>

    ????????
    <!--?OPTIONAL:?include?this?if?you?want?history?support?-->
    ????????
    <iframe?id="__gwt_historyFrame"?style="width:0;height:0;border:0"></iframe>

    ????????
    <h1>InputHint</h1>

    ????????
    <p>
    ????????????你好,輸入前提示演示
    ????????
    </p>

    ????????
    <table?align=center>
    ????????????
    <tr>
    ????????????????
    <td?id="label"></td><td?id="tb"></td>
    ????????????
    </tr>
    ????????????
    <tr>
    ????????????????
    <td></td><td?id="list"?class="sd"></td>
    ????????????
    </tr>
    ????????
    </table>
    ????
    </body>
    </html>

    7.InputHint.gwt.xml
    <module>

    ????
    <!--?Inherit?the?core?Web?Toolkit?stuff.??????????????????-->
    ????
    <inherits?name='com.google.gwt.user.User'/>

    ????
    <!--?Specify?the?app?entry?point?class.???????????????????-->
    ????
    <entry-point?class='mypack.client.InputHint'/>
    ????
    ????
    <servlet?path='/IH_PRO/input_hint'?class='mypack.server.IH_ServiceImpl'/>
    </module>





    posted on 2006-07-14 13:51 方佳瑋 閱讀(3499) 評(píng)論(10)  編輯  收藏 所屬分類: AJAX

    評(píng)論

    # re: [ajax] 用GWT做的輸入前提示 2006-07-14 15:02 peace
    “沒什么注釋,給大家添麻煩了”確實(shí)是這的  回復(fù)  更多評(píng)論
      

    # re: [ajax] 用GWT做的輸入前提示 2006-07-15 10:40 steeven
    有了GWT, Google的產(chǎn)品就不稀奇了 :)  回復(fù)  更多評(píng)論
      

    # re: [ajax] 用GWT做的輸入前提示 2006-07-15 11:51 方佳瑋
    當(dāng)然,我的程序與google的輸入前提示無論算法和功能都無法比,只是模擬一下功能而已  回復(fù)  更多評(píng)論
      

    # re: [ajax] 用GWT做的輸入前提示 2006-07-15 18:43 CowNew開源團(tuán)隊(duì)
    1、public ArrayList getResult();
    沒必要返回值為ArrayList 吧,List九足夠了。
    2、e.printStackTrace();
    小心不知道怎么死的呀。  回復(fù)  更多評(píng)論
      

    # re: [ajax] 用GWT做的輸入前提示 2006-07-15 18:45 方佳瑋
    多謝指導(dǎo),小弟受益了。  回復(fù)  更多評(píng)論
      

    # re: [ajax] 用GWT做的輸入前提示 2006-11-01 16:12 joeney
    公布了群又不讓加,LZ什么意思啊???  回復(fù)  更多評(píng)論
      

    # re: [ajax] 用GWT做的輸入前提示 2006-11-01 16:40 方佳瑋
    大哥,人滿了  回復(fù)  更多評(píng)論
      

    # re: [ajax] 用GWT做的輸入前提示 2006-12-27 16:48 yanghuixia
    謝謝  回復(fù)  更多評(píng)論
      

    # re: [ajax] 用GWT做的輸入前提示 2006-12-28 22:02 yanghuixia
    數(shù)據(jù)庫是怎么連起來的?  回復(fù)  更多評(píng)論
      

    # re: [原創(chuàng)] 用GWT做的輸入前提示 2007-04-27 18:23 張揚(yáng)斌
    不錯(cuò) 學(xué)習(xí)中   回復(fù)  更多評(píng)論
      

    主站蜘蛛池模板: 亚洲av无码一区二区三区四区 | 免费看内射乌克兰女| 亚洲一区无码精品色| 亚洲成在人天堂一区二区| 亚洲中文字幕AV每天更新| 国产激情久久久久影院老熟女免费 | 免费网站观看WWW在线观看| 2020久久精品国产免费| 毛片基地免费视频a| 亚洲一区二区三区偷拍女厕| 亚洲成Av人片乱码色午夜| 亚洲最大中文字幕无码网站| 中文字幕免费在线看线人动作大片| 免费看国产精品3a黄的视频| 亚洲日本乱码在线观看| 亚洲人成色777777老人头| 日本中文字幕免费看| 成人免费黄色网址| 国产精品永久免费视频| 18禁止观看免费私人影院| 亚洲日韩aⅴ在线视频| 亚洲欧美日韩中文字幕一区二区三区| 你好老叔电影观看免费| 日本免费网站视频www区| 亚洲男人的天堂在线va拉文| 亚洲AV综合色区无码二区偷拍| 亚洲AV无码一区二区三区鸳鸯影院| 一级毛片全部免费播放| 亚洲精品视频在线看| 亚洲AV无码专区在线观看成人| 一区二区三区在线免费看| 亚洲人午夜射精精品日韩| 亚洲小说图区综合在线| 最近最新高清免费中文字幕| 妞干网免费观看视频| 67pao强力打造67194在线午夜亚洲 | 亚洲第一区在线观看| 亚洲av色福利天堂| 一级片在线免费看| 亚洲免费观看在线视频| 国产亚洲精品精华液|