<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 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      165 隨筆 :: 17 文章 :: 90 評論 :: 0 Trackbacks

    在工作中需要一個翻頁效果,所以寫下了如下方法。實現了常用的翻頁效果,但代碼還沒有進行優化(缺點:不適合數據量大的情況,因為所有的記錄存在一個Vector變量中)貼出來供需要著參考一下!
    import java.util.*;

    public class Pages {
    ?int allRows;//所有的行數
    ?int currRow;//當前是第幾行
    ?int onePageRows;//一頁顯示多少行
    ?int allPages;//所有的頁數
    ?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=\"首頁\" onClick=\"dealPage();\" id=\"firstPage\" />&nbsp;";
    ??String disabled= "disabled=";
    ??if (!this.firstPage)
    ???disabled= disabled + "disabled";
    ??else
    ???disabled= "";
    ??String button2= "<input type=\"button\" value=\"上頁\" id=\"upPage\" onClick=\"dealPage();\" " + disabled + " />&nbsp;";
    ??if (!this.lastPage)
    ???disabled= disabled + "disabled";
    ??else
    ???disabled= "";
    ??String button3= "<input type=\"button\" value=\"下頁\" id=\"downPage\" onClick=\"dealPage();\" " + disabled + " />&nbsp;";
    ??String button4= "<input type=\"button\" value=\"尾頁\"? id=\"lastPage\" onClick=\"dealPage();\"/>";
    ??String table2= "</td></tr><tr><td align=\"center\">";
    ??String table3= "共" + this.allRows + "行/第" + this.currPage + "頁/共" + this.allPages + "頁</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-03-03 16:45 二胡 閱讀(243) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲欭美日韩颜射在线二| 亚洲男女内射在线播放| 亚洲影视一区二区| 久草免费手机视频| 亚洲va久久久噜噜噜久久天堂| eeuss影院ss奇兵免费com| 免费吃奶摸下激烈视频| 久久精品成人免费国产片小草| 亚洲AV无码一区二区三区国产 | 99在线免费观看视频| 亚洲AV日韩AV高潮无码专区| 久久国产色AV免费观看| 久久综合亚洲色HEZYO社区| www视频免费看| 亚洲国产精品日韩av不卡在线| 国产精品色午夜视频免费看| 在线观看亚洲免费视频| 亚洲精品无码专区久久同性男| 中国一级毛片视频免费看| 亚洲尹人香蕉网在线视颅| 无码一区二区三区免费视频| 国产亚洲精品第一综合| 伊人久久大香线蕉亚洲五月天| 午夜老司机永久免费看片| 国产精品亚洲综合久久| 国产免费小视频在线观看| 岛国岛国免费V片在线观看| 亚洲视频在线免费观看| 四虎影视免费在线| 成人免费av一区二区三区| 亚洲网站在线播放| 国产人妖ts在线观看免费视频| 大妹子影视剧在线观看全集免费 | 亚洲成在人线在线播放无码| 国内精品久久久久久久亚洲| 成人免费的性色视频| 特级毛片全部免费播放| 久久精品国产亚洲AV香蕉| 日韩在线免费播放| 国产成人AV片无码免费| 亚洲欧美日韩中文字幕在线一区|