开发者

How to write Scrollable for Table in j2me by canvas?

Now i try to draw a table by Canvas, but i have a problem, my table doesnt has scrollable.

How can i write some code to help my table can scrollable?

My Code here

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;

/**
 *
 * @author Kency
 */
public class TableCanvas extends Canvas{

    private int w,h;
    private int pad;
    private int cols = 3;
    private int rows = 10;

    public TableCanvas() {
        w = getWidth();
        h = getHeight();


    }




    protected void paint(G开发者_如何转开发raphics g) {
        g.setColor(148, 178, 255);
        g.fillRect(0, 0, w, h);
        for(int i =0 ; i <= cols ; i++){
            g.setColor(0x00D0D0D0);

            for(int j = 0 ; j <= rows ; j++){
                g.drawLine(0, j *  h/rows, cols * w, j* h/rows);
                g.drawLine(i * w/cols, 0, i * w/cols, w * rows);
            }
        }



    }

}


For code like in your excerpt, most straightforward way would probably be with Graphics#translate API.

One would also have to handle key pressed / pointer events to allow user to scroll. Eg when key press corresponds to game action right/left/up/down, you scroll respectively. When pointer is dragged, you find out the direction and, again, scroll respectively

Painting scrollbar(s) would also require "handmade" code.

Another option would be using 3rd party library like LWUIT or J2ME Polish

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜