kuix教程3:用户操作处理

来源:互联网 发布:c语言加密程序 编辑:程序博客网 时间:2024/04/30 03:33

教程3:用户操作处理

Manage users actions管理使用者的行动

 

创建一个框架对象

An action can be associated with a focusable widget (menu item, button, etc.) or with a shortcut event.一个动作都可以与一个可聚焦部件(菜单项,按钮等),或用快捷键事件。 Kuix forwards user actions to the FrameHandler that maintains a frame stack used to process actions. Kuix转发用户操作的FrameHandler,它维护一个框架用来处理行动堆栈。 It as actually a good practice to create one frame per screen because user actions are generally screen dependant.它作为一个很好的做法实际上是创建一个每帧画面通常是因为用户操作的屏幕依赖。

So, let's create a HelloWorldFrame object which will implements the org.kalmeo.util.frame.Frame interface.所以,我们创建一个HelloWorldFrame对象将实现org.kalmeo.util.frame.Frame接口。

Create a Frame object

Push the HelloworldFrame into the FrameHandler:推入FrameHandler的HelloworldFrame:

The FrameHandler manages messages distribution to the frames.该FrameHandler管理信息分配到的帧。 To add your actions handlers, simply register your frame with the FrameHandler.要添加您的行为处理程序,只需注册您的FrameHandler框架。 To do so, add the following lines to the initDesktopContent() on your midlet:为此,添加以下几行到你的MIDlet initDesktopContent():

public void initDesktopContent(Desktop desktop) { // push the frame into the frameHandler Kuix.getFrameHandler().pushFrame(new HelloWorldFrame()); }

Move the content of previous initDesktopContent() method to the HelloWorldFrame.onAdded() method.移动内容的方法以前initDesktopContent()方法到HelloWorldFrame.onAdded()。

 public void onAdded() { // Load the content from the XML file with Kuix.loadScreen static method Screen screen = Kuix.loadScreen("helloworld.xml", null); // Set the application current screen screen.setCurrent(); }

处理“关于”,“退出确认”和“退出”行动

Edit the HelloWorldFrame onMessage method:编辑HelloWorldFrame onMessage方法:

You can also add the following code after the exit action:您还可以添加后退出动作下面的代码:

 public boolean onMessage(Object identifier, Object[] arguments) { if ("about".equals(identifier)) { // display a popup message Kuix.alert("This Helloworld is powered by Kuix", KuixConstants.ALERT_OK); return false; } if ("exitConfirm".equals(identifier)) { // display a popup message Kuix.alert("Are you sure you want to exit?", KuixConstants.ALERT_YES | KuixConstants.ALERT_NO, "exit", null); return false; } if ("exit".equals(identifier)) { // get the midlet instance to invoke the Destroy() method HelloWorld.getDefault().destroyImpl(); //if the event has been processed, we return 'false' to avoid event forwarding to other frames return false; } // return "true" makes the FramHandler to forward the message to the next frame in the stack return true; }

These first 2 actions, use an alert popup box to display some messages.这些行动的第一个2,使用弹出一个警告框来显示一些信息。 See the Kuix Javadocs for more details.查看更详细的情况Kuix的Javadocs。

Once that actions implemented, we need to bind them to the widgets on the screen.一旦行动实施,我们需要将它们绑定到屏幕上的小部件。 Go back to the XML file and add the onAction attribute to the menu items:返回到XML文件,并添加的OnAction属性的菜单项:

 <screenFirstMenu onAction="exit">Exit</screenFirstMenu> <screenSecondmenu> more... <menuPopup> <menuItem onAction="about"> About </menuItem> <menuItem onAction="exitConfirm"> Exit </menuItem> </menuPopup> </screenSecondmenu>

自定义PopupMessage风格

Once again, if you want your popups to display correctly, add several style information to override the default configuration:再次,如果你希望你的弹出窗口显示正确,添加一些样式信息来覆盖默认的配置:

 popupBox { border: 1; border-color: #f19300; bg-color: #77787a; padding: 5; grayed-color: #444447; }

Add buttons添加按钮

We can add "about" and "exit" action on direct touch button.我们可以添加“关于”和“退出直接触摸按钮”的行动。 In this case edit the helloworld.xml to add the folowing lines into the container tag :在这种情况下编辑helloworld.xml添加容器标记folowing线为:

 <button onAction="about">About</button> <button onAction="exitConfirm">Exit</button>

You can optionnaly style the previous buttons in the CSS file:你可以在CSS样式optionnaly上的按钮的文件:

 button { border: 1; border-color: #838386; bg-image: url(title_gradient.png); padding: 1 6 1 6; margin: 2; } button:hover { border-color: #f19300; }

新增“一键”捷径

For Kuix, a shortcut is a simple widget attribute.对于Kuix,快捷方式是一个简单的窗口部件的属性。 If you want to add a shortcut to any component, just set the shortcuts attribute in the XML file like in the following example:如果你想添加一个快捷方式到任何组件,只需设置快捷方式属性的XML文件如下面的例子:

 <menuItem onAction="about" shortcuts="1">About</menuItem > <menuItem onAction="exitConfirm" shortcuts="back|0">Exit</menuItem >

*note: you can add several shortcuts to a widget using a '|' separator between keys. *注:您可以添加多个快捷方式一键之间的一个小部件使用'|'分隔。

Because shortcuts are only available on visible widget, you need to put shortcuts on screen too :由于快捷键只在可见的小工具可用,你需要把屏幕上的快捷方式也:

 <screen title="helloworld" shortcuts="1=about|back=exitConfirm|0=exitConfirm">

Start 启动

Your menu should now be fully operationnal.您的菜单现在应该充分operationnal。 You can try to run the midlet.你可以尝试运行的MIDlet。

Result

原创粉丝点击