TextEditor is an editable text component that is directly drawn on a Canvas or CustomItem.
Engineers with game programming experience must have encountered the need to enter Chinese characters in the game. In this case, the interface is switched to the control window instead of entering English letters or pinyin letters. After Entering Chinese characters, return to the game page. The implementation of TextEditor completely solves this problem.
The main methods of TextEditor include:
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()
When creating a TextEditor instance, instead of using the common new) method, it is implemented through two overloaded factory methods of TextEditor. The parameters of these two methods are slightly different and can be selected as needed.
// 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)
The following code demonstrates how to use 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