简体   繁体   English

如何在J2ME中的画布上制作按钮?

[英]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. 我是J2ME的新手,我试图制作一个页面,该页面的顶部有一些徽标(图像),两个按钮并排排列(一个始终处于选中状态,其中一个始终处于选中状态),并且一个表在下面显示数据按钮。 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. 我正在扩展canvas ,可以制作桌子并绘制图像,但是在Internet上制作按钮时找不到任何东西。 So how should I go about it? 那我该怎么办呢? If anyone could point me to some sample code, that would be great too! 如果有人可以指出一些示例代码,那也很好!

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. 如果它们以正方形排列,则需要跟踪选择了哪个按钮,然后每按一次方向键就更改选定的索引。

iirc my favorite way to paint buttons on canvas was drawing and filling rounded rectangles. iirc我最喜欢在画布上绘制按钮的方法是绘制并填充圆角矩形。 There are methods in Graphics package that do that; Graphics包中有一些方法可以做到这一点。 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 注意,如果要在“按钮”上写文本,请考虑使用Font.getHeightFont.stringWidth确定要绘制的矩形的大小

...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 ? 顺便说一句,为什么不使用Form是有原因的? I ask because StringItem objects, created with appearance BUTTON and having ItemCommandListener look and behave like buttons but are easier to code. 我问是因为StringItem对象是由外观BUTTON创建的,具有ItemCommandListener外观和行为类似于按钮,但更易于编码。 The rest also looks doable with Form , one just may need CustomItem to display the table like you describe 其余的看起来也可以使用Form ,其中一个可能只需要CustomItem来显示表,就像您描述的那样

The default UI does not have buttons, only commands. 默认的UI没有按钮,只有命令。 You have to make one yourself or use a GUI framework like LWUit. 您必须自己动手或使用LWUit之类的GUI框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM