package Method;
|
import java.awt.Color;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import javax.swing.Box;
|
import javax.swing.JPanel;
|
|
import ColorAndFont.buttonTitle;
|
import PbuliClass.JButtonModel;
|
import PbuliClass.JlableModel;
|
|
/**±¾ÀàÓÃÓÚÑ¡ÔñÒ³Âë*/
|
public class PageSelect {
|
JPanel mb=null;
|
JButtonModel firstPageButton=null;
|
JButtonModel latePageButton=null;
|
JButtonModel nextPageButton=null;
|
JButtonModel lastPageButton=null;
|
String a;
|
String serch;
|
int k;
|
int maxPageNumber;
|
static int currentPageNumber = 1;//µ±Ç°Ò³Ãæ
|
int allrows;//Êý¾Ý×ÜÌõÊý
|
JPanel south=null;
|
JlableModel nowpage;//µ±Ç°Ò³Âë
|
String hang;//ÿҳÏÔʾµÄÐÐÊý
|
String data_name;//Êý¾Ý¿âµÄÃû³Æ
|
|
public String getHang() {
|
return hang;
|
}
|
public String getSerch() {
|
return serch;
|
}
|
|
public void setHang(String hang) {
|
this.hang = hang;
|
}
|
|
public String getData_name() {
|
return data_name;
|
}
|
|
public void setData_name(String data_name) {
|
this.data_name = data_name;
|
}
|
|
|
public int getAllrows() {
|
return allrows;
|
}
|
|
public void setAllrows(int allrows) {
|
this.allrows = allrows;
|
}
|
|
public JPanel get_page_mb() {
|
mb=new JPanel();
|
mb.setBackground(Color.WHITE);//ÉèÖÃÃæ°å±³¾°Îª°×É«
|
Box topicBox = Box.createHorizontalBox();// ´´½¨Ò»¸öˮƽÏäÈÝÆ÷
|
topicBox.add(getFirstPageButton());
|
topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getLatePageButton());
|
topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getNextPageButton());
|
topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getLastPageButton());
|
nowpage= new JlableModel("µÚ"+currentPageNumber+"Ò³");
|
topicBox.add(Box.createHorizontalStrut(25));// Ìí¼ÓÒ»¸ö15ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(nowpage);
|
mb.add(topicBox );
|
return mb;
|
}
|
|
public JButtonModel getFirstPageButton() {
|
if(firstPageButton==null) {
|
firstPageButton=new JButtonModel(buttonTitle.getHome());
|
firstPageButton.setEnabled(false);
|
firstPageButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
currentPageNumber=1;
|
nowpage.setText("µÚ"+currentPageNumber+"Ò³");
|
lastPageButton.setEnabled(true);
|
nextPageButton.setEnabled(true);
|
k=Integer.parseInt(getHang());
|
serch="select * from "+getData_name() +" limit 0,"+k;
|
currentPageNumber = 1;
|
firstPageButton.setEnabled(false);
|
latePageButton.setEnabled(false);
|
}
|
});
|
}
|
return firstPageButton;
|
}
|
|
public JButtonModel getLatePageButton() {
|
if(latePageButton==null) {
|
latePageButton=new JButtonModel(buttonTitle.getPrevious());
|
latePageButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
lastPageButton.setEnabled(true);
|
latePageButton.setEnabled(true);
|
--currentPageNumber;
|
nowpage.setText("µÚ"+currentPageNumber+"Ò³");
|
if(currentPageNumber==1) {
|
latePageButton.setEnabled(false);
|
firstPageButton.setEnabled(false);
|
}
|
if(currentPageNumber>=1) {
|
k=Integer.parseInt(getHang());
|
a=String.valueOf(currentPageNumber*k-k);
|
serch="select * from "+getData_name() +" limit "+a+","+k;
|
nextPageButton.setEnabled(true);
|
}
|
}
|
});
|
}
|
return latePageButton;
|
}
|
|
public JButtonModel getNextPageButton() {
|
if(nextPageButton==null) {
|
nextPageButton=new JButtonModel(buttonTitle.getNext());
|
nextPageButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
++currentPageNumber;
|
nowpage.setText("µÚ"+currentPageNumber+"Ò³");
|
k=Integer.parseInt(getHang());
|
a=String.valueOf(currentPageNumber*k-k);
|
serch="select * from "+getData_name() +" limit "+a+","+k;
|
if(currentPageNumber!=1) {
|
firstPageButton.setEnabled(true);
|
latePageButton.setEnabled(true);
|
}
|
if (currentPageNumber == maxPageNumber) {
|
nextPageButton.setEnabled(false);
|
lastPageButton.setEnabled(false);
|
}
|
|
|
}
|
});
|
}
|
return nextPageButton;
|
}
|
|
public JButtonModel getLastPageButton() {
|
if(lastPageButton==null) {
|
lastPageButton=new JButtonModel(buttonTitle.getLast());
|
lastPageButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
nextPageButton.setEnabled(false);
|
lastPageButton.setEnabled(false);
|
k=Integer.parseInt(getHang());
|
a=String.valueOf(getMaxPageNumber()*k-k);
|
serch="select * from "+getData_name() +" limit "+a+","+k;
|
latePageButton.setEnabled(true);
|
firstPageButton.setEnabled(true);
|
currentPageNumber=getMaxPageNumber();
|
nowpage.setText("µÚ"+currentPageNumber+"Ò³");
|
|
}
|
});
|
|
}
|
return lastPageButton;
|
}
|
|
public int getMaxPageNumber() {
|
double k=Integer.parseInt(getHang());
|
double j=getAllrows()/k;
|
return maxPageNumber=(int) Math.ceil(j);
|
//Math.ceil() º¯Êý·µ»Ø´óÓÚ»òµÈÓÚÒ»¸ö¸ø¶¨Êý×ÖµÄ×îСÕûÊý
|
}
|
|
|
}
|