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

发布于 2024-12-03 12:00:14 字数 185 浏览 0 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

晚雾 2024-12-10 12:00:14

iirc 我最喜欢在画布上绘制按钮的方法是绘制和填充圆角矩形。 Graphics 包可以做到这一点;为了获得所需的效果,我只是使用相同或相差一的参数来调用它们,我不记得确切了。

  • 请注意,如果您要在“按钮”上书写文本,请考虑使用 Font.getHeightFont.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.

  • 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

遮云壑 2024-12-10 12:00:14

没那么难,但是你需要自己画所有的东西。这意味着,按钮要么使用中间有文本的普通矩形(不同的颜色可以指示突出显示的文本),要么它们可以是您自己制作的图像。

如果它们排列在正方形中,您需要跟踪选择了哪个按钮,然后在按下方向键时更改所选索引。

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.

困倦 2024-12-10 12:00:14

默认 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文