?? mycalendar.java
字號:
package MyCalendar;
import javax.microedition.lcdui.*;
public class MyCalendar
extends CustomItem
implements ItemCommandListener {
private final static Command CMD_EDIT = new Command("Select",
Command.ITEM, 1);
private Display display;
private int rows = 6;//定義表格行數
private int cols = 7;//定義表格列數
private int dx = 20;//定義表格寬度
private int dy = 20;//定義表格高度
private int currentX = 0;//當前的行數
private int currentY = 0;//當前的列數
private String[][] data = new String[rows][cols];
public MyCalendar(String title, Display d) {
super(title);
display = d;
setDefaultCommand(CMD_EDIT);
setItemCommandListener(this);
int interactionMode = getInteractionModes();
}
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 w, int h) {
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);
}
int oldColor = g.getColor();
g.setColor(0x00D0D0D0);
//填充灰色方格
g.fillRect((currentX * dx) + 1, (currentY * dy) + 1, dx - 1, dy - 1);
g.setColor(oldColor);
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (data[i][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][j], (j * dx) + 5, ((i + 1) * dy) - 3,
Graphics.BOTTOM | Graphics.LEFT);
// 保存原來的畫布信息
g.setClip(oldClipX, oldClipY, oldClipWidth, oldClipHeight);
}
}
}
}
protected boolean traverse(int dir, int viewportWidth, int viewportHeight,
int[] visRect_inout) {
switch (dir) {
case Canvas.DOWN:
if (currentY < (rows - 1)) {
currentY++;
repaint(currentX * dx, (currentY - 1) * dy, dx, dy);
repaint(currentX * dx, currentY * dy, dx, dy);
} else
return false;
break;
case Canvas.UP:
if (currentY > 0) {
currentY--;
repaint(currentX * dx, (currentY + 1) * dy, dx, dy);
repaint(currentX * dx, currentY * dy, dx, dy);
} else
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);
}
}
visRect_inout[0] = currentX;
visRect_inout[1] = currentY;
visRect_inout[2] = dx;
visRect_inout[3] = dy;
return true;
}
public void setText(String text) {
data[currentY][currentX] = text;
repaint(currentY * dx, currentX * dy, dx, dy);
}
public void commandAction(Command c, Item i) {
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -