📄 calcscreen.java
字号:
import javax.microedition.lcdui.*;
/**
* 该类描述了计算器的显示区,用于显示输入的操作数及计算结果。
*/
public class CalcScreen extends CustomItem {
private String text;
private Font showFont;
public CalcScreen() {
super(null);
showFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
text = "";
}
protected int getMinContentHeight() {
return showFont.getHeight() + 4;
}
protected int getMinContentWidth() {
return showFont.stringWidth("012345678901234.-") + 4;
}
protected int getPrefContentHeight(int width) {
return getMinContentHeight();
}
protected int getPrefContentWidth(int height) {
return 150;
}
protected void paint(Graphics g, int w, int h) {
g.setColor(160, 160, 255);
g.drawRect(0, 0, w-1, h-1);
g.setColor(210, 210, 255);
g.drawRect(2, 2, w-5, h-5);
g.setColor(0, 0, 0);
g.setFont(showFont);
g.drawString(text, w-10, h-3, Graphics.BOTTOM|Graphics.RIGHT);
}
public void setText(String text) {
this.text = text;
repaint();
}
public String getText() {
return text;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -