简体   繁体   English

在J2ME画布表单中使用事件?

[英]Using event in j2me canvas forms?

I'm a dot net developer. 我是一个点网开发人员。 And recently forced to do something in j2me. 并且最近被迫在j2me中做某事。

We have app in j2me for working with SMS-Text-Message and make different UI based on these sms. 我们在j2me中有一个用于处理SMS-Text-Message的应用程序,并根据这些短信制作了不同的UI。 In this app form create manually with Canvas . 在此应用程序表单中,使用Canvas手动创建。

There are several operations (which executable via selection of different options by user) in each canvas. 每个画布中有几种操作(可通过用户选择不同的选项来执行)。 Some of these operation create new canvas (something like multi Form show ). 其中一些operation create new canvas (类似于multi Form show)。

Is there solution to define event in each canvas form and then after calling so some operation (like create new canvas). 是否有解决方案来定义每个画布形式中的事件,然后在调用后进行一些操作(如创建新画布)。

More Info: 更多信息:

For Example I have blow Code (Canvas-Form): 例如我有打击代码(画布形式):

public void keyPressed(int key) {
        if (key == -3) {
            // call OK-event 
        }
    }

It means when user input specific key like, event call to back to base midlet .(in this case Canvas-Form and midlet are in different java classes). 这意味着当用户输入特定的键(例如,事件调用)以返回到基本midlet (在这种情况下, Canvas-Formmidlet在不同的Java类中)。

To do this in Dot net , We define event in Canvas-Form , then call it. 为此,在点网中 ,我们以Canvas-Form定义事件,然后调用它。 Also we handle that event in midlet-class and write own code int that handle-method 此外,我们在midlet-class处理该事件,并编写自己的代码int处理方法

So my Question Is How do same thing's in J2me? 所以我的问题是J2me中的情况如何?

More and More Additional Info(Update 2) 越来越多的其他信息(更新2)

My knowledge about java and j2me is less than Alga knowledge about this:). 我对java和j2me的了解少于Alga对这一点的了解:)。 So maybe my question seems ridiculous. 所以也许我的问题似乎很荒谬。 But my Question has these parts: 但是我的问题包括以下部分:

1) Define Event (I don't know how!) 1)定义事件(我不知道如何!)
2) Call Event (where I write call OK-event comment in code sample) 2)呼叫事件(我在代码示例中编写call OK-event注释)
3) Handle Event Method (I don't know how!) 3)处理事件方法(我不知道怎么做!)

I my search, I see a lot of examples how to define event with command. 在我的搜索中,我看到了许多示例如何使用命令定义事件。 But in canvas form should I define Command to do this or, no need to Command because I draw buttons in canvas. 但是我应该以画布形式定义Command来执行此操作,或者不需要Command因为我在画布上绘制了按钮。 I hope someone can understand my problem with this description. 我希望有人可以通过此说明理解我的问题。

And hope it prevent Downvotes :) 并希望它能阻止Downvotes :)

This is quite easy to do. 这很容易做到。 Canvas can listen to key press and pointer events, as well as to commands. Canvas可以侦听按键和指针事件以及命令。 You implement the operations you need in respective methods defined in the API. 您可以在API中定义的相应方法中实现所需的操作

If you're interested, find more details on that in Canvas API documentation . 如果您有兴趣,请在Canvas API文档中找到有关此内容的更多详细信息。

To create new canvas is also easy since these are plain old Java objects, no magic.You seem to be mostly active in C#, expect it to be pretty much like you create instances of C# objects. 创建新画布也很容易,因为它们是普通的旧Java对象,没有魔术。您似乎在C#中非常活跃,希望它就像在创建C#对象的实例一样。

The only specifics worth remembering is that to make your canvas (or any Displayable for that matter) visible, you need an instance of Display that corresponds to your application. 唯一需要记住的细节是,要使您的画布(或与此相关的任何Displayable )可见,您需要一个与您的应用程序相对应的Display实例。 The only way to obtain that instance is from the class that extends MIDlet - from the class that serves as an entry point to your MIDP application. 获取该实例的唯一方法是从扩展MIDlet的类中获得-从用作MIDP应用程序入口点的类中获得。

You have to get the Display instance there and further make sure that it's available anywhere you need it. 您必须将Display实例放在那儿,并进一步确保它在您需要的任何地方都可用。 That instance is also a plain Java object, pretty similar to C# object and the ways to expose it are nothing MIDP-specific. 该实例也是一个普通的Java对象,与C#对象非常相似,并且公开它的方式也不是MIDP特定的。

If you need to learn more details, consider also studying references to tutorials and API documentation at 如果您需要了解更多详细信息,请考虑同时在以下位置学习对教程和API文档的参考:


For the code snippet provided in question update, the way to find out what's going on there would be to add appropriate logging and re-test it in emulator, looking into emulator console when you press keys. 对于问题更新中提供的代码段,找出问题所在的方法是添加适当的日志记录,然后在模拟器中对其进行重新测试,并在按下按键时进入模拟器控制台。

public void keyPressed(int key) {
        // add logging here:
        System.out.println("keyPressed [" + key + "]");
        if (key == -3) {
            // add logging here:
            System.out.println("calling OK-event");
            // call OK-event 
        }
}

For a sample code, check lcdui tag wiki, there's a reference to "MIDP event Handling" tutorial, in EventEx3.java . 有关示例代码,请检查lcdui标签Wiki,在EventEx3.java中有对“ MIDP事件处理”教程的EventEx3.java Another tutorial listed in lcdui tag wiki worth looking at is "J2ME Tutorial: User Interfaces with MIDP 2.0", section Working with the Low-Level API - there is sample code as well. 值得一看的lcdui标签wiki中列出的另一个教程是“ J2ME教程:使用MIDP 2.0的用户界面”, 使用低级API部分 -也提供了示例代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM