pageEndRow = totalRows;
} else {
pageEndRow = startRow + pageSize;
}
}
public void previous() {
if (currentPage == 1) {
return;
}
currentPage--;
startRow = (currentPage - 1) * pageSize;
pageStartRow = startRow + 1;
this.hasFlagSet(currentPage, totalPages);
if (this.hasNextPage == 0) {
pageEndRow = totalRows;
} else {
pageEndRow = startRow + pageSize;
}
}
public void next() {
if (currentPagetotalPages) {
currentPage++;
}
startRow = (currentPage - 1) * pageSize;
pageStartRow = startRow + 1;
this.hasFlagSet(currentPage, totalPages);
if (this.hasNextPage == 0) {
pageEndRow = totalRows;
} else {
pageEndRow = startRow + pageSize;
}
}
public void last() {
currentPage = totalPages;
startRow = (currentPage - 1) * pageSize;
pageStartRow = startRow + 1;
this.hasFlagSet(currentPage, totalPages);
if (this.hasNextPage == 0) {
pageEndRow = totalRows;
} else {
pageEndRow = startRow + pageSize;
}
}
public void refresh(int _currentPage) {
currentPage = _currentPage;
if (currentPagetotalPages) {
last();
}
this.hasFlagSet(currentPage, totalPages);
}
private void hasFlagSet(int currentPage, int totalPages) {
if (currentPage == totalPages) {
if (currentPage == 1) {
this.hasPreviousPage = 0;
this.hasNextPage = 0;
} else {
this.hasPreviousPage = 1;
this.hasNextPage = 0;
}
} else {
if (currentPage == 1) {
this.hasPreviousPage = 0;
this.hasNextPage = 1;
} else {
this.hasPreviousPage = 1;
this.hasNextPage = 1;
}
}
}
}
这是我的工程里的分页核心代码,希望对你有用,还有ssh分页文档,可以参照研究一下 。
JAVA高手能否告知,JAVA如何实现自动从文件夹读取文件并翻页显示图片你自己改了 。图片切换效果已经做出来了
package com.east.lesson11.swing;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class CardDemo extends JFrame {
CardLayout cl=null;
JPanel cp=null;
public CardDemo(){
super("卡片式布局");
}
public void init(){
cl=new CardLayout();
cp=new JPanel();
JButton pre=new JButton("上一张");
pre.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
cl.previous(cp);
}
});
JButton next=new JButton("下一张");
next.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
cl.next(cp);
}
});
JPanel np=new JPanel();
np.add(pre);
np.add(next);
add(np,BorderLayout.NORTH);
cp.setLayout(cl);
try {
Image img1=ImageIO.read(new File("image/allseeds.png"));
JLabel l1=new JLabel();
l1.setIcon(new ImageIcon(img1));
cp.add(l1,"img1");//对于CardLayout,和其他Layout不一样,要为卡片添加名字img1
Image img2=ImageIO.read(new File("image/menu.png"));
JLabel l2=new JLabel();
l2.setIcon(new ImageIcon(img2));
cp.add(l2,"img2");
Image img3=ImageIO.read(new File("03.jpg"));
JLabel l3=new JLabel();
l3.setIcon(new ImageIcon(img3));
cp.add(l3,"img3");
Image img4=ImageIO.read(new File("04.jpg"));
JLabel l4=new JLabel();
l3.setIcon(new ImageIcon(img4));
推荐阅读
- 飞行小人手机游戏,飞行小人手机游戏怎么玩
- 电脑的内存显卡怎么查型号,电脑内存和显卡怎么看
- 鸿蒙系统怎样调出侧屏,鸿蒙系统侧滑功能
- 手机直播为啥填写错误,为什么直播认证失败
- vb.net中换行 vbnet label 自动换行
- 苹果cms播放器排序,苹果cmsv10播放器
- 鸿蒙系统找不到手机卡了,升级鸿蒙sim卡读不出来
- 关于html5canvasas3的信息
- vb转哈vb.net vb转app