📄 updpaymenttbl.java
字号:
package src.com.j2meclient.citation;
import javax.microedition.lcdui.*;
public class UpdPaymentTbl extends CustomItem implements ItemCommandListener{
private Command CMD_EDIT;
private Display display;
private static final int UPPER = 0;
private int location = UPPER+1;
private static final int IN = 1;
private static final int LOWER = 2;
private int rows = 0;
private int cols = 3;
private int dx = 79;
private int dy = 25;
private int currentX = 0;
private int currentY = 0;
private String[][] data = null;
// Traversal stuff
// indicating support of horizontal traversal internal to the CustomItem
boolean horz;
// indicating support for vertical traversal internal to the CustomItem.
boolean vert;
public UpdPaymentTbl(String title, Display d){
super(title);
CMD_EDIT = new Command("修改", Command.ITEM, 1);
display = d;
setDefaultCommand(CMD_EDIT);
setItemCommandListener(this);
int interactionMode = getInteractionModes();
// System.out.println("interactionMode======="+interactionMode);
horz = ((interactionMode & CustomItem.TRAVERSE_HORIZONTAL) != 0);
vert = ((interactionMode & CustomItem.TRAVERSE_VERTICAL) != 0);
}
public void setData(String[][] drawData,int i){
rows = i+1;
this.data = drawData;
}
public void setText(String text) {
data[currentY-1][currentX] = text;
repaint(currentY * dx, currentX * dy, dx, dy);
}
public int getRowsCount(){
return rows-1;
}
public String[][] getTbl(){
return data;
}
public void commandAction(Command c, Item i) {
if (c == CMD_EDIT) {
TextInput textInput = new TextInput(data[currentY-1][currentX], this, display);
display.setCurrent(textInput);
}
}
protected int getMinContentHeight() {
return (rows * dy) + 1;
}
protected int getMinContentWidth() {
return (cols * dx) + 1;
}
protected int getPrefContentHeight(int width) {
return (rows * dy) + 1;
}
protected int getPrefContentWidth(int height) {
return (cols * dx) + 1;
}
protected void paint(Graphics g, int arg1, int arg2) {
// TODO Auto-generated method stub
int color = g.getColor();
g.setColor(0xFFFFFF);
// g.fillRect(0,0,getMinimumWidth(),getMinimumHeight());
g.fillRect(0,0,79,25);
g.setColor(color);
for (int i = 0; i <= rows; i++) {
g.drawLine(0, i * dy, cols * dx, i * dy);
}
for (int i = 0; i <= cols; i++) {
g.drawLine(i * dx, 0, i * dx, rows * dy);
}
for(int n = 0;n < 4;n++){
// g.setColor(0xCCCCFF );
// g.fillRect(((n+currentX) * dx) + 1, (currentY * dy) + 1, (dx*(n+1)) - 1, dy - 1);
g.setColor(0x0B0002);
g.drawLine(n * dx, 0, n * dx , dy);
}
g.setColor(0xCCCCFF );
g.fillRect((currentX * dx) + 1, (currentY * dy) + 1, dx - 1, dy - 1);
g.setColor(0x0B0002);
for(int m = 0;m < 3;m++){
String data[] ={"方式","日期","金额"};
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE));
g.drawString(data[m], (m * dx) + 25, dy - 2,Graphics.BOTTOM | Graphics.LEFT);
}
for (int i = 1 ; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (data[i-1][j] != null) {
// store clipping properties
int oldClipX = g.getClipX();
int oldClipY = g.getClipY();
int oldClipWidth = g.getClipWidth();
int oldClipHeight = g.getClipHeight();
g.setClip((j * dx) + 1, i * dy, dx - 1, dy - 1);
g.drawString(data[i-1][j], (j * dx) + 2, ((i + 1) * dy) - 2,
Graphics.BOTTOM | Graphics.LEFT);
// restore clipping properties
g.setClip(oldClipX, oldClipY, oldClipWidth, oldClipHeight);
}
}
}
}
protected boolean traverse(int dir, int viewportWidth, int viewportHeight, int[] visRect_inout) {
if (horz && vert) {
switch (dir) {
case Canvas.DOWN:
if (location == UPPER) {
location = IN;
} else {
if (currentY < (rows - 1)) {
currentY++;
repaint(currentX * dx, (currentY - 1) * dy, dx, dy);
repaint(currentX * dx, currentY * dy, dx, dy);
} else {
location = LOWER;
return false;
}
}
break;
case Canvas.UP:
if (location == LOWER) {
location = IN;
} else {
if (currentY > 1) {
currentY--;
repaint(currentX * dx, (currentY + 1) * dy, dx, dy);
repaint(currentX * dx, currentY * dy, dx, dy);
} else {
location = UPPER;
return false;
}
}
break;
case Canvas.LEFT:
if (currentX > 0) {
currentX--;
repaint((currentX + 1) * dx, currentY * dy, dx, dy);
repaint(currentX * dx, currentY * dy, dx, dy);
}
break;
case Canvas.RIGHT:
if (currentX < (cols - 1)) {
currentX++;
repaint((currentX - 1) * dx, currentY * dy, dx, dy);
repaint(currentX * dx, currentY * dy, dx, dy);
}
}
} else if (horz || vert) {
switch (dir) {
case Canvas.UP:
case Canvas.LEFT:
if (location == LOWER) {
location = IN;
} else {
if (currentX > 0) {
currentX--;
repaint((currentX + 1) * dx, currentY * dy, dx, dy);
repaint(currentX * dx, currentY * dy, dx, dy);
} else if (currentY > 0) {
currentY--;
repaint(currentX * dx, (currentY + 1) * dy, dx, dy);
currentX = cols - 1;
repaint(currentX * dx, currentY * dy, dx, dy);
} else {
location = UPPER;
return false;
}
}
break;
case Canvas.DOWN:
case Canvas.RIGHT:
if (location == UPPER) {
location = IN;
} else {
if (currentX < (cols - 1)) {
currentX++;
repaint((currentX - 1) * dx, currentY * dy, dx, dy);
repaint(currentX * dx, currentY * dy, dx, dy);
} else if (currentY < (rows - 1)) {
currentY++;
repaint(currentX * dx, (currentY - 1) * dy, dx, dy);
currentX = 0;
repaint(currentX * dx, currentY * dy, dx, dy);
} else {
location = LOWER;
return false;
}
}
}
} else {
// In case of no Traversal at all: (horz|vert) == 0
}
visRect_inout[0] = currentX;
visRect_inout[1] = currentY;
visRect_inout[2] = dx;
visRect_inout[3] = dy;
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -