📄 unicodepanel.java
字号:
public static class UnicodePanel extends JComponent {
protected char base; // 指定我们显示的初始值
protected Font font = new Font("serif", Font.PLAIN, 18); // 指定缺省的显示字体
protected Font headingfont = new Font("monospaced", Font.BOLD, 18); // 指定缺省表头字体
static final int lineheight = 25; // 指定显示一行高度
static final int charspacing = 20; // 指定显示一个Unicode字符宽度
static final int x0 = 65;
static final int y0 = 40;
/** 指定开始显示的初始字符,并且刷新Panel */
public void setBase(char base) {
this.base = base;
repaint();
}
/**设定显示所用的新字体或者风格并且刷新Panel */
public void setFont(String family, int style) {
this.font = new Font(family, style, 18);
repaint();
}
/** 绘出字符表的一页 */
public void paintComponent(Graphics g) {
int start = (int)base & 0xFFF0; // 设置起始显示字符
// 使用给定字体显示表头
g.setFont(headingfont);
// 在顶端绘出0..F
for(int i=0; i < 16; i++) {
String s = Integer.toString(i, 16);
g.drawString(s, x0 + i*charspacing, y0-20);
}
// 绘出左边表头.
for(int i = 0; i < 16; i++) {
int j = start + i*16;
String s = Integer.toString(j, 16);
g.drawString(s, 10, y0+i*lineheight);
}
// 绘出Unicode字符
g.setFont(font);
char[] c = new char[1];
for(int i = 0; i < 16; i++) {
for(int j = 0; j < 16; j++) {
c[0] = (char)(start + j*16 + i);
g.drawChars(c, 0, 1, x0 + i*charspacing, y0+j*lineheight);
}
}
}
/** 返回给定的分辨率 */
public Dimension getPreferredSize() {
return new Dimension(x0 + 16*charspacing,
y0 + 16*lineheight);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -