如何通过按键关闭J2ME应用程序 [英] How to close a J2ME application by key pressing

查看:84
本文介绍了如何通过按键关闭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í仅在内部画布类.但是destroyAppnotifyDestroyed是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应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆