📄 unicodedisplay.java
字号:
// 导入所需要的Java类库
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class UnicodeDisplay extends JFrame implements ActionListener {
int page = 0;
UnicodePanel p;
JScrollBar b;
String fontfamily = "Serif";
int fontstyle = Font.PLAIN;
/**
* 构造函数,创建frame、菜单和滚动条
**/
public UnicodeDisplay(String name) {
super(name);
p = new UnicodePanel(); // 创建panel
p.setBase((char)(page * 0x100)); // 初始化panel
getContentPane().add(p, "Center"); // 使其居中
// Create and set up a scrollbar, and put it on the right
b = new JScrollBar(Scrollbar.VERTICAL, 0, 1, 0, 0xFF);
b.setUnitIncrement(1);
b.setBlockIncrement(0x10);
b.addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
page = e.getValue();
p.setBase((char)(page * 0x100));
}
});
getContentPane().add(b, "East");
// 设置消息响应函数处理关闭窗口请求
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { System.exit(0); }
});
// 响应PageUP、PageDown、Up和Down按键
this.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
int code = e.getKeyCode();
int oldpage = page;
if ((code == KeyEvent.VK_PAGE_UP) ||
(code == KeyEvent.VK_UP)) {
if (e.isShiftDown()) page -= 0x10;
else page -= 1;
if (page < 0) page = 0;
}
else if ((code == KeyEvent.VK_PAGE_DOWN) ||
(code == KeyEvent.VK_DOWN)) {
if (e.isShiftDown()) page += 0x10;
else page += 1;
if (page > 0xff) page = 0xff;
}
if (page != oldpage) { //如果改变了当前显示页...
p.setBase((char) (page * 0x100)); // 更新显示
b.setValue(page); // 更新滚动条
}
}
});
// 建立可以改变显示字体的菜单.
JMenuBar menubar = new JMenuBar();
this.setJMenuBar(menubar);
menubar.add(makemenu("Font Family",
new String[] {"Serif", "SansSerif", "Monospaced"},
this));
menubar.add(makemenu("Font Style",
new String[]{
"Plain","Italic","Bold","BoldItalic"
}, this));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -