S40 Touch API - Text Editor API
TextEditor是一個(gè)可編輯的文本組件,它直接繪制在Canvas或CustomItem上。
有過(guò)游戲編程經(jīng)驗(yàn)的工程師一定碰到過(guò)需要在游戲中輸入中文的情況。遇到這種情況,不是索性用輸入英文或拼音字母代替,就是將界面切換到使用控件的窗口,待輸入完中文后,再返回游戲頁(yè)面。TextEditor的實(shí)現(xiàn),徹底解決了這個(gè)問(wèn)題。
TextEditor的主要方法包括:
boolean register( x, y, maxFps, maxPps, FrameAnimatorListenerlistener)
void unregister()
boolean isRegistered()
static int getNumRegisteredFrameAnimators();
void drag(x, y)
void kineticScroll( int startSpeed, int direction, int friction, float angle )
void stop()
在創(chuàng)建TextEditor的實(shí)例的時(shí)候,不是使用常用的new()方法,而是通過(guò)TextEditor 的兩個(gè)重載的工廠(chǎng)方法實(shí)現(xiàn)的。這兩個(gè)方法的參數(shù)略有不同,可根據(jù)實(shí)際情況選擇使用。
// Creates a new empty TextEditor with the given maximum size in characters, constraints and editor size as number of visible rows.
static TextEditor createTextEditor(int maxSize, int constraints, int width, int rows)
// Creates a new TextEditor object with the given initial contents, maximum size in characters, constraints and editor size in pixels.
static TextEditor createTextEditor(java.lang.String text, int maxSize, int constraints, int width, int height)
下面的代碼演示了如何使用TextEditor:
TextEditor editor=TextEditor.createTextEditor("abc", 20, TextField.ANY, getWidth()-20, 100);
editor.setMultiline(true);
editor.setVisible(true);
editor.setFocus(true);
editor.setPosition(10, 10);
editor.setParent(this); // this point to a Canvas