📄 inputmatrixcanvas.java
字号:
package edu.neu.aatk.canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import edu.neu.aatk.AATK;
import edu.neu.aatk.Calculator;
import edu.neu.aatk.textbox.MyTextBox;
public class InputMatrixCanvas extends AATKCanvas {
public int xValue;
public int yValue;
public int xFocus = 0;
public int yFocus = 0;
private String info = "use setInfo(String str)";
public boolean numberPressed = false;
public int keyCode;
public MyTextBox[][] mtbs;
public InputMatrixCanvas(String title, AATK aatk, int xValue, int yValue) {
super(title, aatk);
this.xValue = xValue;
this.yValue = yValue;
int xPos = 5;
int yPos = 75;
mtbs = new MyTextBox[xValue][yValue];
for(int i = 0; i < xValue; i ++) {
for (int j = 0; j < yValue; j ++) {
mtbs[i][j] = new MyTextBox(xPos,yPos);
xPos += MyTextBox.WIDTH + 5;
}
yPos += MyTextBox.HEIGHT + 5;
xPos = 5;
}
}
public void setInfo(String str) {
info = str;
}
protected void paint(Graphics g) {
super.paint(g);
paintInfo(g);
paintLeftCommand(g, "返回");
paintRightCommand(g, "确定");
paintGrayBox(g);
paintBox(g);
}
protected void paintInfo(Graphics g) {
Font font = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_UNDERLINED,
Font.SIZE_LARGE);
g.setColor(0, 0, 0);
g.setFont(font);
g.drawString(info, 120, 50, Graphics.TOP | Graphics.HCENTER);
}
protected void paintGrayBox(Graphics g) {
int xPos = 5;
int yPos = 75;
g.setColor(200, 200, 200);
for(int i = 0; i < 8; i ++) {
for (int j = 0; j < 8; j ++) {
g.drawRect(xPos, yPos, MyTextBox.WIDTH, MyTextBox.HEIGHT);
xPos += MyTextBox.WIDTH + 5;
}
yPos += MyTextBox.HEIGHT + 5;
xPos = 5;
}
}
protected void paintBox(Graphics g) {
for(int i = 0; i < xValue; i ++) {
for (int j = 0; j < yValue; j ++) {
mtbs[i][j].drawTextBox(g);
mtbs[i][j].drawString(g);
}
}
if(numberPressed) {
try {
mtbs[xFocus][yFocus].insert(g, keyCode);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
mtbs[xFocus][yFocus].focused(g);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -