/*
create time: 2008-8-30 Administrator
*/
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class PageMessage extends MIDlet {
public cCanvas canvas;
public PageMessage() {
canvas = new cCanvas();
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
Display.getDisplay(this).setCurrent(canvas);
}
}
class cCanvas extends Canvas {
public String message[][] = { { "订单号", "股票名称", "价格", "数量" },
{ "bbb", "bbb", "bbb", "bbb" }, { "ccc", "bbb", "bbb", "bbb" },
{ "ddd", "bbb", "bbb", "bbb" }, { "eee", "bbb", "bbb", "bbb" },
{ "fff", "bbb", "bbb", "bbb" }, { "ggg", "bbb", "bbb", "bbb" } };
private static int startindex, currentindex, LINENUM = 3, COLNUM = 4;
public cCanvas() {
}
protected void paint(Graphics g) {
g.setColor(255, 255, 255); //刷屏
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0); //设置显示字体颜色
drawPageStudentMessage(g);
drawSoftKey(g); //画左右键
}
public void drawSoftKey(Graphics g) {
g.setColor(0); //设置显示字体颜色
g.drawString("返回", 2, getHeight() - 2, Graphics.LEFT | Graphics.BOTTOM);
g.drawString("下页", getWidth() - 2, getHeight() - 2, Graphics.RIGHT
| Graphics.BOTTOM);
}
//数据内容,实现翻页功能
public void drawPageStudentMessage(Graphics g) {
for (int currentindex = startindex; (currentindex < startindex
+ LINENUM)
&& currentindex < message.length; currentindex++) {
for (int col = 0; col < COLNUM; col++) {
g.drawString(message[currentindex][col], 60 * col,
20 * (currentindex % LINENUM), Graphics.LEFT
| Graphics.TOP);
}
}
}
public static int page;
protected void keyPressed(int keyCode) {
if (keyCode == -7) //点击右键 翻页
{
if (page < message.length / LINENUM)
page++;
startindex = (page * LINENUM);
}
if (keyCode == -6) //点击左键 翻页
{
if (page > 0)
page--;
startindex = (page * LINENUM);
}
repaint();
}
}