如何在J2ME中的画布上制作按钮?
我是 J2ME 新手,我试图制作一个页面,顶部有一些徽标(图像),两个并排排列的按钮(始终选择其中一个且只有一个)以及一个显示下面数据的表格按钮。根据当前选择的按钮显示数据。我正在扩展 canvas
并且能够制作表格并绘制图像,但我在互联网上找不到任何有关制作按钮的信息。那么我该怎么办呢?如果有人能给我一些示例代码,那就太好了!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
iirc 我最喜欢在画布上绘制按钮的方法是绘制和填充圆角矩形。 Graphics 包可以做到这一点;为了获得所需的效果,我只是使用相同或相差一的参数来调用它们,我不记得确切了。
Font.getHeight
和Font.stringWidth
来确定要绘制的矩形的大小顺便说一句,您是否有理由不使用 <代码>表单?我问这个问题是因为
StringItem
对象是用外观BUTTON
创建的,并且具有ItemCommandListener
的外观和行为类似于按钮,但更容易编码。其余的看起来也可以使用Form
完成,只是可能需要CustomItem
来显示您所描述的表格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.
Font.getHeight
andFont.stringWidth
to determine size of rectangle to draw aroundBTW is there a reason why you don't use
Form
? I ask becauseStringItem
objects, created with appearanceBUTTON
and havingItemCommandListener
look and behave like buttons but are easier to code. The rest also looks doable withForm
, one just may needCustomItem
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.
默认 UI 没有按钮,只有命令。您必须自己制作一个或使用 LWUit 等 GUI 框架。
The default UI does not have buttons, only commands. You have to make one yourself or use a GUI framework like LWUit.