如何通过按键关闭J2ME应用程序

编程入门 行业动态 更新时间:2024-10-28 04:16:51
本文介绍了如何通过按键关闭J2ME应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Eclipse中有一个带有Nokia SDK插件的J2ME项目,在其中使用了Canvas外观.用户将按一个键退出该应用程序. 但是我真的不知道按键事件后关闭的方式.

I have a J2ME project in Eclipse with Nokia SDK plugin, in which I use a Canvas skin. The users will press a key to quit the application. But I don''t really know the way to close after key pressing event. Help me, please!

推荐答案

一种简单的方法(可能不太优雅,具体取决于您编写Midlet的方式):创建画布时,请执行像这样: 在您的Midlet中,将对Midlet本身的引用传递给Canvas构造函数: One simple way (which may not be very elegant, depending on how you have written your midlet): When you create your canvas, do it something like this: in your Midlet, pass a reference to the Midlet itself to your Canvas constructor: MyCanvas theCanvas = new MyCanvas(this, ...);

在Canvas构造函数中,保存Midlet参考:

in the Canvas constructor, save the Midlet reference:

class MyCanvas extends Canvas implements CommandListener { MyMidlet theMidlet; public MyCanvas(MyMidlet m, ...) { this.theMidlet = m; ... } ... }

然后,当您要从MyCanvas中的keyPressed关闭Midlet时, 只需致电theMidlet.destroyApp() 彼得

Then, when you want to close the midlet from keyPressed in MyCanvas, just call theMidlet.destroyApp() Peter

在您的keyPressed处理程序中,只需调用destroyApp(true). 如果您的Midlet在外部终止,则系统会调用destroyApp,并且应该执行任何清理操作并调用notifyDestroyed(). In your keyPressed handler, just call destroyApp(true). destroyApp is what the system calls if your midlet is terminated externally, and it should do any cleanup required and call notifyDestroyed().

您知道,keyPressedí仅在内部画布类.但是destroyApp和notifyDestroyed是MIDlet类的方法. 如何在我的keyPressed处理程序中调用destroyApp(true)? 请更清楚地向我解释. You know, keyPressed í available just inside the Canvas class. But the destroyApp and notifyDestroyed are methods of MIDlet class. How can we call destroyApp(true) in my keyPressed handler? Please explain me more clearly.

更多推荐

如何通过按键关闭J2ME应用程序

本文发布于:2023-11-27 22:49:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639929.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按键   应用程序   J2ME

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!