tipycalFlow
tipycalFlow

Reputation: 7644

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 the internet. So how should I go about it? If anyone could point me to some sample code, that would be great too!

Upvotes: 1

Views: 1782

Answers (3)

gnat
gnat

Reputation: 6223

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

Upvotes: 2

funkybro
funkybro

Reputation: 8671

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.

Upvotes: 2

Mister Smith
Mister Smith

Reputation: 28158

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

Upvotes: 1

Related Questions