pagecounter.java

来自「textviewer 一个手机上的文本浏览器实现」· Java 代码 · 共 75 行

JAVA
75
字号
package textViewer;// TODO: implement as RangedIntegerpublic class PageCounter {    private int page;    private PageChangable callback;    private int min;    private int max;    public PageCounter(PageChangable callback, int page, int min, int max)     {    	this.callback = callback;	this.page = page;	this.min = min;	this.max = max;    }    public PageCounter(PageChangable callback)     {	this(callback, 1,1,1);     }    public int getMax()    {	return max;    }    public void setMax(int max)    {	this.max = max;    }    public int getValue()     {	return page;    }    public void setValueWithErrors(int newPage) throws IndexOutOfBoundsException    {	if ( (newPage >= min) && (newPage <= max) )	    {		page = newPage;		callback.pageChanged();	    }	else {throw new IndexOutOfBoundsException("PageCounter.setValueWithErrors: requested page number " + Integer.toString(newPage) + " is not in between minimum limit " + Integer.toString(min) + " and maximum limit " + Integer.toString(max));}    }	    public void setValue(int newPage)    {	try {	    setValueWithErrors(newPage);	} catch (IndexOutOfBoundsException e) {}    }    public void add(int arg)     {	setValue(getValue() + arg);    }    public void addAsFarAsYouCan(int arg)     {	try {	    setValueWithErrors(getValue() + arg);	}	catch (IndexOutOfBoundsException e) 	    {		if (arg > 0) {setValue(max);}		else if (arg < 0) {setValue(min);}	    }    }}

⌨️ 快捷键说明

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