⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page.java

📁 基于java的医院门诊管理系统
💻 JAVA
字号:
package crqs.util;

import java.io.Serializable;
import java.util.*;

public class Page implements Serializable{
	private int LINES_PER_PAGE = 20;	//每页所显示的行数
	private ArrayList pageCollection;	//存储记录
	private int pages = 1;				//分页数
	private int current = 1;			//当前页
	
	public Page(){
		
	}
	public Page(ArrayList array){
		this.setCollection(array);
		this.parse();
	}
	
	public Page(ArrayList array, int num){
		this.setCollection(array);
		this.LINES_PER_PAGE=num;
		this.parse();
	}
	
	public void setLines(int lines){
		this.LINES_PER_PAGE = lines;
		this.parse();
	}
	public int getLines(){
		return this.LINES_PER_PAGE;
	}
	
	public int getPages(){
		return this.pages;
	}
	public int getCurrentPage(){
		return this.current;
	}
	public ArrayList setCurrentPage(int page){
		return this.indexof(page);
	}
	
	public void setCollection(ArrayList lst){
		this.pageCollection = (ArrayList)lst.clone();
	}
	public ArrayList getCollection(){
		return this.pageCollection;
	}
	
	//分页函数
	public void parse(){
		int size = this.pageCollection.size();
		this.pages = size > 0? (size+this.LINES_PER_PAGE-1)/this.LINES_PER_PAGE
				: this.pages;
	}
	
	//返回指定页的记录
	public ArrayList indexof(int page){
		int lbounds;
		if(page > this.pages)
			current = this.pages;
		else if(page <= 0)
			current = 1;
		else
			current = page;
		lbounds = (current-1)*LINES_PER_PAGE;
		int hbounds = ((lbounds+LINES_PER_PAGE) > pageCollection.size())
		? pageCollection.size() :(lbounds+LINES_PER_PAGE);
		ArrayList lst = new ArrayList();
		for(int i = 0; i < hbounds-lbounds; i++)
			lst.add(pageCollection.get(lbounds+i));
		return lst;		
	}
	
	//当前页的前一页
	public ArrayList previous(){
		return this.indexof(this.current-1);
	}
	//当前页的后一页
	public ArrayList next(){
		return this.indexof(this.current+1);
	}
	
	//定位到首页
	public ArrayList gotoFirst(){
		return this.indexof(1);
	}
	//定位到最后一页
	public ArrayList gotoLast(){
		return this.indexof(this.pages);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -