开发者

How to make buttons on a canvas in J2ME?

I'm new to J2ME and I was trying to make a page which has some logos(images) at the top, two buttons arranged side-by-side(one and only one of which is always selected) and a table displaying data below the buttons. The data is displayed according to which button is currently selected. I'm extending canvas and I was able to make the tables and draw the images but I could'nt find anything on making buttons on 开发者_Go百科the internet. So how should I go about it? If anyone could point me to some sample code, that would be great too!


iirc my favorite way to paint buttons on canvas was drawing and filling rounded rectangles. There are methods in Graphics package that do that; to get desired effect I just called them with same or off-by-one parameters I don't recall exactly.

  • note if you are going to write text over "buttons", consider using Font.getHeight and Font.stringWidth to determine size of rectangle to draw around

...logos(images) at the top, two buttons arranged side-by-side(one and only one of which is always selected) and a table displaying data below the buttons

BTW is there a reason why you don't use Form? I ask because StringItem objects, created with appearance BUTTON and having ItemCommandListener look and behave like buttons but are easier to code. The rest also looks doable with Form, one just may need CustomItem to display the table like you describe


Not that hard, but you need to draw everything yourself. That means, buttons are either using a plain rectangle with text in the middle (different colours could indicate which is highlighted), or they could be images which you made yourself.

If they are arranged in a square, you need to keep track of which button is selected, and then change the selected index whenever a direction key is pressed.


The default UI does not have buttons, only commands. You have to make one yourself or use a GUI framework like LWUit.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜