Here a simple code snipplet, for entering a one-liner with editing
A "raw" solution without using any API functionality.
This grabs the raw Event data directly and translates all standard Latin characters to chars, added
to your textline.
Plus using the Back-Delete and Enter key.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| String chatstring="";
....
g.drawString(chatstring, 20, 20);
g.drawString(chatstring+(System.currentTimeMillis()%500>250?"|":""), 20, 50);
.... public boolean handleEvent(Event paramEvent) {
if(paramEvent.id==401) { if(paramEvent.key>=32 && paramEvent.key<=122) chatstring+=(char)paramEvent.key; if(paramEvent.key==8 && chatstring.length() > 0) chatstring = chatstring.substring(0, chatstring.length() - 1); if(paramEvent.key==10 && chatstring.length() > 0) {sendChat(chatstring); chatstring="";} }
return true; } |