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

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

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

    憨厚生

    ----Java's Slave----
    ***Java's Host***

      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      165 隨筆 :: 17 文章 :: 90 評(píng)論 :: 0 Trackbacks

    在工作中需要一個(gè)翻頁(yè)效果,所以寫下了如下方法。實(shí)現(xiàn)了常用的翻頁(yè)效果,但代碼還沒有進(jìn)行優(yōu)化(缺點(diǎn):不適合數(shù)據(jù)量大的情況,因?yàn)樗械挠涗洿嬖谝粋€(gè)Vector變量中)貼出來(lái)供需要著參考一下!
    import java.util.*;

    public class Pages {
     int allRows;//所有的行數(shù)
     int currRow;//當(dāng)前是第幾行
     int onePageRows;//一頁(yè)顯示多少行
     int allPages;//所有的頁(yè)數(shù)
     int currPage= 1;
     boolean firstPage= false;
     boolean lastPage= false;

     public Pages(int onePageRows) {
      this.onePageRows= onePageRows;
     }
    /*
       vector1 為所有的記錄
    */

     public Vector downPage(Vector vector1, int currPage) {
      Vector vector= new Vector();
      this.currPage= currPage;
      this.allRows= vector1.size();
      this.currRow= currPage * (this.onePageRows);
      int j= this.allRows % this.onePageRows;
      this.allPages= (this.allRows / this.onePageRows) + (j == 0 ? 0 : 1);
      this.currPage++;
      if (this.currPage < this.allPages) {
       this.lastPage= true;
      } else {
       this.lastPage= false;
      }
      this.firstPage= true;
      int i= 0;
      for (i= 0; i < this.onePageRows && currPage * this.onePageRows + i < this.allRows; i++) {
       vector.add(i, vector1.get(currRow + i));
      }
      this.currRow= this.currRow + i;
      return vector;
     }

     public Vector upPage(Vector vector1, int currPage) {
      Vector vector= new Vector();
      this.currPage= currPage;
      this.allRows= vector1.size();
      this.currRow= (currPage - 2) * (this.onePageRows);
      int j= this.allRows % this.onePageRows;
      this.allPages= (this.allRows / this.onePageRows) + (j == 0 ? 0 : 1);
      this.currPage--;
      if (this.currPage > 1) {
       this.firstPage= true;
      } else {
       this.firstPage= false;
      }
      this.lastPage= true;
      for (int i= 0; i < this.onePageRows; i++) {
       vector.add(i, vector1.get(this.currRow + i));
      }
      return vector;
     }
     public Vector firstPage(Vector vector1) {
      Vector vector= new Vector();
      this.allRows= vector1.size();
      this.currRow= this.onePageRows;
      int j= this.allRows % this.onePageRows;
      this.allPages= (this.allRows / this.onePageRows) + (j == 0 ? 0 : 1);
      this.firstPage= false;
      if (allPages > 1)
       this.lastPage= true;
      for (int i= 0; i < this.onePageRows && i < vector1.size(); i++) {
       vector.add(i, vector1.get(i));
      }
      return vector;
     }
     public Vector lastPage(Vector vector1) {
      Vector vector= new Vector();
      this.allRows= vector1.size();
      int j= this.allRows % this.onePageRows;
      this.allPages= (this.allRows / this.onePageRows) + (j == 0 ? 0 : 1);
      this.currPage= this.allPages;
      this.lastPage= false;
      if (allPages > 1)
       this.firstPage= true;
      int m= j == 0 ? this.onePageRows : this.allRows - (this.allPages - 1) * this.onePageRows;
      int n= m;
      for (int i= 0; i < m; i++) {
       vector.add(i, vector1.get(this.allRows - n));
       n--;
      }
      return vector;
     }

     public String getToolBar() {
      String form= "<form  id=\"form\" method=\"post\">";
      String table1= "<table align=\"center\" width=\"70%\"><tr><td>";
      String button1= "<input type=\"button\" value=\"首頁(yè)\" onClick=\"dealPage();\" id=\"firstPage\" />&nbsp;";
      String disabled= "disabled=";
      if (!this.firstPage)
       disabled= disabled + "disabled";
      else
       disabled= "";
      String button2= "<input type=\"button\" value=\"上頁(yè)\" id=\"upPage\" onClick=\"dealPage();\" " + disabled + " />&nbsp;";
      if (!this.lastPage)
       disabled= disabled + "disabled";
      else
       disabled= "";
      String button3= "<input type=\"button\" value=\"下頁(yè)\" id=\"downPage\" onClick=\"dealPage();\" " + disabled + " />&nbsp;";
      String button4= "<input type=\"button\" value=\"尾頁(yè)\"  id=\"lastPage\" onClick=\"dealPage();\"/>";
      String table2= "</td></tr><tr><td align=\"center\">";
      String table3= "共" + this.allRows + "行/第" + this.currPage + "頁(yè)/共" + this.allPages + "頁(yè)</td></tr></table></form>";
      String result= form + table1 + button1 + button2 + button3 + button4 + table2 + table3;
      return result;
     }
     
     public String getJavaScript() {
      StringBuffer result= new StringBuffer();
      if (this.getAllRows() > this.getOnePageRows()) {
       result.append("<SCRIPT language=JavaScript>");
       result.append("function dealPage(){");
       result.append("document.all.form.action=\"/mydomain/javaoa/selectqh.do?method=\"+event.srcElement.id+\"&currPage=");
       result.append(this.getCurrPage() + "&onePageRows=" + this.getOnePageRows() + "\";");
       result.append("document.all.form.submit();");
       result.append("}");
       result.append("</SCRIPT>");
      }
      return result.toString();
     }
     // public static void main(String[] args) {
     //  Pages page= new Pages(5);
     //  Vector vector= new Vector();
     //  Vector vector1= new Vector();
     //  for (int i= 0; i < 7; i++) {
     //   vector.add(i, new String(new Integer(i).toString()));
     //  }
     //  vector1= page.upPage(vector, 2);
     //  String s= page.getJavaScript();
     //  System.out.println("==" + s);
     //     for (int i= 0; i < vector1.size(); i++) {
     //      System.out.println(i + "=" + vector1.get(i));
     //     }
     //     System.out.println("allRows=" + page.allRows);
     //     System.out.println("currRow=" + page.currRow);
     //     System.out.println("onePageRows=" + page.onePageRows);
     //     System.out.println("allPages=" + page.allPages);
     //     System.out.println("currPage=" + page.currPage);
     //     System.out.println("firstPage=" + page.firstPage);
     //     System.out.println("lastPage=" + page.lastPage);
     // }
     /**
      * @return
      */
     public int getAllPages() {
      return allPages;
     }

     /**
      * @return
      */
     public int getAllRows() {
      return allRows;
     }

     /**
      * @return
      */
     public int getCurrPage() {
      return currPage;
     }

     /**
      * @return
      */
     public int getCurrRow() {
      return currRow;
     }

     /**
      * @return
      */
     public boolean isFirstPage() {
      return firstPage;
     }

     /**
      * @return
      */
     public boolean isLastPage() {
      return lastPage;
     }

     /**
      * @return
      */
     public int getOnePageRows() {
      return onePageRows;
     }

    }

    posted on 2007-01-23 14:15 二胡 閱讀(510) 評(píng)論(4)  編輯  收藏 所屬分類: Java

    評(píng)論

    # re: 實(shí)現(xiàn)翻頁(yè)效果的一個(gè)方法 2007-01-31 22:15 FG
    你和健寒真是絕配阿,都這么專業(yè)!呵呵呵   回復(fù)  更多評(píng)論
      

    # re: 實(shí)現(xiàn)翻頁(yè)效果的一個(gè)方法 2007-02-12 11:14 JieJr
    原來(lái)分頁(yè)這么麻煩,不過你可以每次用的時(shí)候簡(jiǎn)單一些哈!  回復(fù)  更多評(píng)論
      

    # re: 實(shí)現(xiàn)翻頁(yè)效果的一個(gè)方法[未登錄] 2007-03-03 17:06 J
    是不是比原來(lái)漂亮一些?  回復(fù)  更多評(píng)論
      

    # re: 實(shí)現(xiàn)翻頁(yè)效果的一個(gè)方法 2007-12-29 12:05 laoflch
    其實(shí)將分頁(yè)的工作交給數(shù)據(jù)庫(kù)去做的話,效率會(huì)更好些。  回復(fù)  更多評(píng)論
      

    主站蜘蛛池模板: 永久免费AV无码国产网站| 国产免费网站看v片在线| 亚洲宅男永久在线| 亚洲爽爽一区二区三区| 天天看片天天爽_免费播放| 99久在线国内在线播放免费观看| 亚洲理论在线观看| 亚洲色成人中文字幕网站| 国产一级理论免费版| 日韩精品无码免费专区午夜不卡| 黄色免费在线观看网址| 亚洲精品久久无码| 亚洲中文字幕无码av在线| 国产成人免费ā片在线观看| 很黄很色很刺激的视频免费| 99久久综合精品免费| 无码人妻AV免费一区二区三区| 91在线免费观看| 久久精品国产亚洲av麻豆蜜芽| 久久久久亚洲精品成人网小说| 亚洲人成网站色在线入口| 今天免费中文字幕视频| igao激情在线视频免费| 一边摸一边爽一边叫床免费视频| 无码天堂亚洲国产AV| 国产成人亚洲综合无| 自拍偷自拍亚洲精品偷一| 亚洲精品9999久久久久无码| 中文字幕无码精品亚洲资源网久久| 国产成人精品日本亚洲直接| 亚洲人成网站18禁止久久影院 | 亚洲人成色99999在线观看| 亚洲成人网在线播放| 亚洲永久中文字幕在线| 亚洲精品国产福利在线观看| 亚洲黑人嫩小videos| 亚洲视频在线观看视频| 亚洲国产成人va在线观看网址| 亚洲同性男gay网站在线观看| 亚洲AV综合色区无码二区爱AV| 亚洲AV无码一区二区三区牛牛|