黑莓应用程序中的菜单项
我在应用程序中使用了一些菜单项,并且对我覆盖的运行方法有疑问。
private MenuItem menuItemUpdate = new MenuItem("Update", 0, 0) {
public void run() {
// Can I write GUI code here?
}
};
正如评论所述,我可以在这里编写 GUI 代码吗?我不行吗?因为我不在 GUI 线程上?当我有更改 GUI 的代码时,是否应该使用 invokeLater 方法?那么对话框呢,是否也应该在 invokeLater 方法中调用它们?
如果我创建了另一个线程,当用户选择菜单项时将调用该线程,是否有必要覆盖 MenuItem 的运行方法?我可以在构造函数中启动该线程吗?并使 run 方法不被重写?
I use some menuitems in my application and I have a question about the run method which I override.
private MenuItem menuItemUpdate = new MenuItem("Update", 0, 0) {
public void run() {
// Can I write GUI code here?
}
};
As the comment states, can I write GUI code here? I can`t right? Since I am not on the GUI thread? Should I use the invokeLater-method when I have code that changes the GUI? And what about Dialogs, should they be invoked in invokeLater-methods as well?
And is it necassary to override the run-method of MenuItem if I have made another thread which will be invoked when the user selects the menu item? Could I start that thread in the constructor instead? And leave the run method un-overridden?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在那里编写 UI 代码,因为 UI 线程处理用户的操作,并调用菜单项代码。所有用户交互均由 UI 线程处理。
You can write UI code there, because the UI thread handles the user's actions, and calls the menu item code. All user interaction is handled by the UI thread.
是的,你可以 - 因为它是在 UI 线程上,例如:
并且似乎一般规则是你不要添加任何锁定 - 直到你得到一个 IllegalStateException ;-)
Yes, you can - because it's on the UI thread, for example:
And it seems to be general rule that you don't add any locking around - until you get an IllegalStateException ;-)