📄 mytextbox.java
字号:
package edu.neu.aatk.textbox;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
public class MyTextBox {
public static final int maxLength = 2;
public static final int WIDTH = 24;
public static final int HEIGHT = 18;
private int length = 0;
public int pos = 0;
private StringBuffer numString = new StringBuffer("");
private int num;
private int xPos;
private int yPos;
public MyTextBox(int xPos, int yPos) {
this.xPos = xPos;
this.yPos = yPos;
}
public void drawTextBox(Graphics g) {
g.setColor(0, 0, 0);
g.drawRect(xPos, yPos, WIDTH, HEIGHT);
}
public void insert(Graphics g, int keyCode) throws Exception {
Font font = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN,
Font.SIZE_LARGE);
g.setFont(font);
if(++ length <= 2) {
numString.append(keyCode - 48);
g.drawString(numString.toString(),
xPos + 4, yPos - 1,
Graphics.TOP | Graphics.LEFT);
pos ++;
}
else {
g.drawString(numString.toString(),
xPos + 4, yPos - 1,
Graphics.TOP | Graphics.LEFT);
throw new Exception("位数不得大于2");
}
}
public void delete() {
numString.delete(0, numString.length());
length = 0;
pos = 0;
}
public int getNumber() {
num = Integer.parseInt(numString.toString());
return num;
}
public void focused(Graphics g) {
g.setColor(255, 0, 0);
g.drawRect(xPos, yPos, 24, 18);
g.setColor(0, 0, 0);
g.drawString(numString.toString(),
xPos + 4, yPos - 1,
Graphics.TOP | Graphics.LEFT);
}
public void drawString(Graphics g) {
g.drawString(numString.toString(),
xPos + 4, yPos - 1,
Graphics.TOP | Graphics.LEFT);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -