?? pagecontroller.java
字號:
package prj13_1;
import java.util.ArrayList;
//負責傳入一個大的集合,根據頁號返回所需要的數據
/*
* 頁數=
記錄條數%每頁條數==0 記錄條數/每頁條數
否則 記錄條數/每頁條數+1
第N頁顯示第幾條記錄(記錄從0開始算)? (N-1)*每頁條數=<序號< N*每頁條數
* */
public class PageController {
private ArrayList bigList; //大的集合,外界傳入
private int curentPageIndex = 1; //當前頁號,外界傳入
private int countPerpage = 5; //每頁條數,外界可以設定
private ArrayList smallList; //小的集合,返回
private int pageCount; //頁數
private int recordCount; //記錄條數
private int prePageIndex; //上一頁序號
private int nextPageIndex; //下一頁序號
private boolean firstPage; //是否第一頁
private boolean lastPage; //是否最后一頁
public void setCurentPageIndex(int curentPageIndex) { //每當頁數改變,都會調用這個函數,篩選代碼可以寫在這里
this.curentPageIndex = curentPageIndex;
//上一頁,下一頁確定
prePageIndex = curentPageIndex - 1;
nextPageIndex = curentPageIndex + 1;
//是否第一頁,最后一頁
if(curentPageIndex==1){
firstPage = true;
}
else{
firstPage = false;
}
if(curentPageIndex==pageCount){
lastPage = true;
}
else{
lastPage = false;
}
//篩選工作
smallList = new ArrayList();
for(int i=(curentPageIndex-1)*countPerpage; i<curentPageIndex*countPerpage&&i<recordCount; i++){
smallList.add(bigList.get(i));
}
}
public int getCurentPageIndex() {
return curentPageIndex;
}
public ArrayList getBigList() {
return bigList;
}
public void setBigList(ArrayList bigList) {
this.bigList = bigList;
//計算條數
recordCount = bigList.size();
//計算頁數
if(recordCount%countPerpage==0){
pageCount = recordCount/countPerpage;
}
else{
pageCount = recordCount/countPerpage + 1;
}
}
public int getCountPerpage() {
return countPerpage;
}
public void setCountPerpage(int countPerpage) {
this.countPerpage = countPerpage;
}
public ArrayList getSmallList() {
return smallList;
}
public void setSmallList(ArrayList smallList) {
this.smallList = smallList;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getRecordCount() {
return recordCount;
}
public void setRecordCount(int recordCount) {
this.recordCount = recordCount;
}
public int getNextPageIndex() {
return nextPageIndex;
}
public void setNextPageIndex(int nextPageIndex) {
this.nextPageIndex = nextPageIndex;
}
public int getPrePageIndex() {
return prePageIndex;
}
public void setPrePageIndex(int prePageIndex) {
this.prePageIndex = prePageIndex;
}
public boolean isFirstPage() {
return firstPage;
}
public void setFirstPage(boolean firstPage) {
this.firstPage = firstPage;
}
public boolean isLastPage() {
return lastPage;
}
public void setLastPage(boolean lastPage) {
this.lastPage = lastPage;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -