📄 multistringdisplay.java
字号:
import java.util.Vector;
public class MultiStringDisplay extends Display {
private Vector body = new Vector(); // 打印的字串
private int columns = 0; // 最大字数
public void add(String msg) { // 新增字串
body.add(msg);
updateColumn(msg);
}
public int getColumns() { // 字数
return columns;
}
public int getRows() { // 行数
return body.size();
}
public String getRowText(int row) { // 该行的內容
return (String)body.get(row);
}
private void updateColumn(String msg) { // 更新字数
if (msg.getBytes().length > columns) {
columns = msg.getBytes().length;
}
for (int row = 0; row < body.size(); row++) {
int fills = columns - ((String)body.get(row)).getBytes().length;
if (fills > 0) {
body.set(row, body.get(row) + spaces(fills));
}
}
}
private String spaces(int count) { // 产生空白
StringBuffer buf = new StringBuffer();
for (int i = 0; i < count; i++) {
buf.append(' ');
}
return buf.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -