如何更改 J2ME 表单内 CustomItem 的大小?
如何更改 J2ME 表单内 CustomItem
的大小?我创建了一个 CustomItem
(javax.microedition.lcdui.CustomItem
的派生类)并将其放置在一个表单(javax.microedition.lcdui 的派生类)中。表格
)。一些事件触发后,我想更改 CustomItem
的高度和宽度。我应该如何更改我的代码?
How can I change the size of a CustomItem
inside a form in J2ME? I created a CustomItem
(derived class of javax.microedition.lcdui.CustomItem
) and placed it inside a form (of derived class of javax.microedition.lcdui.Form
). After some event triggers, I want to change the CustomItem
's height and width. How should I change my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 MIDP 中,CustomItem 由封闭容器 Form 呈现。 MIDP 不提供通知其父级其大小已更改的方法;所以这个行为必须在你的代码中手工设计。
假设您的事件是在用户按下 OK (FIRE) 时触发的,那么您将需要调用 repaint() 或 repaint(x,y,w,h)。此重绘调用会导致绘制整个 CustomItem 或仅绘制矩形部分。这又会调用您的(CustomItem 的)paint() 方法,您可以在其中绘制更大尺寸的组件。
In MIDP, CustomItem is rendered by the enclosing container, the Form. MIDP doesn't provide a way to notify it's parent that it's size has changed; so this behavior has to be handcrafted in your code.
Suppose your event is fired upon the user pressing OK (FIRE), then you will need to call either repaint() OR repaint(x,y,w,h). This repaint call causes either entire CustomItem to be painted or just the rectangular portion. This inturn calls your paint() method (of CustomItem) where you can draw a larger sized component.
我得到了解决方案。我们应该为新的 CustomItem 创建一个具有新属性的新对象。然后从表单中删除现有的 CustomItem,并在表单中添加新的 CustomItem。
I got the solution. We should create a new object for the new CustomItem with new properties.Then delete the existing CustomItem from the form and add the new CustomItem inside the form.