📄 pageclient.java
字号:
package day03;
import java.io.*;
import java.sql.*;
public class PageClient {
private int pageSize;
private int currentPage = 1;
private PageTool tool = new PageTool();
private String[] UI = { "开始程序(i) 退出(其他任意键)", "请出入页面长度:",
"上一页(u) 下一页(d) 指定页(p) 返回(b)", "请输入页码: " };
public String prompt(String message) {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String command = "";
System.out.println(message);
int num = 1;
try {
while ("".equals((command = in.readLine()).trim())) {
System.out.println(++num + "->");
}
} catch (IOException e) {
e.printStackTrace();
}
return command;
}
public static void main(String[] args) {
PageClient c = new PageClient();
while (c.runOrNot()) {
while (c.readOrNot()) {
}
}
}
private boolean readOrNot() {
String command = prompt(UI[2]);
if ("u".equals(command)) {
if (currentPage > 1) {
System.out.print(tool.getPage(--currentPage));
}
} else if ("d".equals(command)) {
if (currentPage < tool.countPageNum()) {
System.out.print(tool.getPage(++currentPage));
}
} else if ("p".equals(command)) {
String pn = prompt(UI[3] + "(总页数" + tool.countPageNum() + "页");
currentPage = Integer.parseInt(pn);
if (currentPage > 0 && currentPage <= tool.countPageNum()) {
System.out.print(tool.getPage(currentPage));
}
} else if ("b".equals(command)) {
return false;
}
return true;
}
private boolean runOrNot() {
String command = prompt(UI[0]);
if ("i".equals(command)) {
command = prompt(UI[1]);
try {
pageSize = Integer.parseInt(command);
System.out.println(pageSize);
tool.setPageSize(pageSize);
} catch (Exception e) {
e.printStackTrace();
}
} else {
return false;
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -