看到有人詢問Kuix安裝,而且運作Demo出現問題,其實在用過的幾個UI包中,Kuix算是安裝最簡單的了,基本上隻要包括Kuix和Kutil兩個jar包就可以,這兩個包在http://www.kalmeo.org/projects/kuix/download可以下載下傳,其中Kutil提供基礎類庫,比如Textarea中的xml解析器就在這個包中,同時建議下載下傳源代碼,因為要做比較強大應用的話,這個包還是有不少問題的,不是bug,而是功能較弱,以後我會專門出一篇介紹Kuix的不足之處和改善方法.安裝步驟如下:
下載下傳最新的WTK,并安裝,配置(具體搜尋相關的文章),注意網上部分開源J2ME的包對于低版本的WTK是不能運作的,目前我用的是2.5.2.
引入Kuix,Kutil包,并做下圖的配置.記得不要把J2ME的包删掉,Kuix還是基于J2Me的包的,雖然不用直接繼承J2ME的任何基類.
建立Midlet suit,接着不用建立Midlet了,而是繼承KuixMIDlet,然後依照指南建立Frame和XML
midlet代碼,需要加載fram和css樣式,直接複制KuixDemo的樣式和圖檔即可.
public class Helloworld extends KuixMIDlet {
public Helloworld() {
// TODO Auto-generated constructor stub
}
public void initDesktopContent(Desktop arg0) {
Kuix.getFrameHandler().pushFrame(new HelloworldFrame());
}
public void initDesktopStyles() {
Kuix.loadCss("style.css");
}
}
frame代碼,這是我示範動态資料綁定的demo:
public class HelloworldFrame implements Frame {
public void onAdded() {
// TODO Auto-generated method stub
Screen screen = Kuix.loadScreen("hello.xml", null);
screen.setCurrent();
}
public boolean onMessage(Object identifier, Object[] arguments) {
// TODO Auto-generated method stub
if ("about".equals(identifier)) {
Kuix.alert(Kuix.getMessage("CREDITS"), KuixConstants.ALERT_OK);
return false;
}
if ("exitConfirm".equals(identifier)) {
// display a popup message
Kuix.alert(Kuix.getMessage("EXIT_CONFIRM"), 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;
}
if ("showDynamic".equals(identifier)) {
Kuix.getFrameHandler().pushFrame(new Dynamic());
return false;
}
if ("showCombo".equals(identifier)) {
Kuix.getFrameHandler().pushFrame(new combo());
return false;
}
// return "true" makes the FramHandler to forward the message to the next frame in the stack
return true;
}
public void onRemoved() {
// TODO Auto-generated method stub
}
}
hello.xml
<?xml version="1.0" encoding="UTF-8"?>
<screen shortcuts="1=about|back=exitConfirm|0=exitConfirm">
<_title>%HELLOWORLD%</_title>
<container style="layout:inlinelayout(false,fill); align:center">
<text><_text>%HELLOWORLD%</_text></text>
<picture src="logo.png" />
<button onAction="showDynamic">%DYNAMIC_DISPLAY%</button>
<button onAction="showCombo">combo dynamic</button>
<button onAction="about">%ABOUT%</button>
<button onAction="exitConfirm">%EXIT%</button>
</container>
<screenFirstMenu onAction="exit">Exit</screenFirstMenu>
<screenSecondmenu>
%MORE%
<menuPopup>
<menuItem onAction="about" shortcuts="1">
%ABOUT%
</menuItem>
<menuItem onAction="exitConfirm" shortcuts="back|0">
%EXIT%
</menuItem>
</menuPopup>
</screenSecondmenu>
</screen>
這樣就可以運作了.另外如果需要修改代碼的話建立添加source link,選擇項目,右鍵,properties,java build path,source标簽,點link source按鈕,添加Kuix和Kutil源碼的目錄,這樣就可以多個項目共享Kuix的源碼,又可以友善的直接修改源碼.