hello my friends
my code is the followed
Code:
import javax.microedition.lcdui.Canvas;import =
javax.microedition.lcdui.Font;import javax.microedition.lcdui.Graphics; =
public =
class =
CustomInputCanvas extends Canvas implements Runnable{ static final char[] KEY_NUM1_CHARS =3D new char[]{'.', '?', '!'}; static final char[] KEY_NUM2_CHARS =3D new char[]{'a', 'b', 'c'}; static final char[] KEY_NUM3_CHARS =3D new char[]{'d', 'e', 'f'}; static final char[] KEY_NUM4_CHARS =3D new char[]{'g', 'h', 'i'}; static final char[] KEY_NUM5_CHARS =3D new char[]{'j', 'k', 'l'}; static final char[] KEY_NUM6_CHARS =3D new char[]{'m', 'n', 'o'}; static final char[] KEY_NUM7_CHARS =3D new char[]{'p', 'q', 'r', 's'}; static final char[] KEY_NUM8_CHARS =3D new char[]{'t', 'u', 'v'}; static final char[] KEY_NUM9_CHARS =3D new char[]{'w', 'x', 'y', 'z'}; static final char[] KEY_NUM0_CHARS =3D new char[]{' =
'}; int clearKeyCode =3D Integer.MIN_VALUE; StringBuffer currentText =3D new StringBuffer(); String currentString =3D =
new String(); int lastPressedKey =3D Integer.MIN_VALUE; int currentKeyStep =3D 0; Font inputFont =3D null; int inputWidth =3D 0; int inputHeight =3D 0; int inputTranslationX =3D 0; long lastKeyTimestamp =3D 0; long maxKeyDelay =3D 500L; int caretIndex =3D 0; int caretLeft =3D 0; boolean caretBlinkOn =3D true; long caretBlinkDelay =3D 500L; long lastCaretBlink =3D 0; boolean goToNextChar =3D true; =
public =
CustomInputCanvas() { new Thread(this).start(); inputFont =3D Font.getDefaultFont(); inputWidth =3D getWidth(); inputHeight =3D inputFont.getHeight(); } public char[] getChars(int key) { switch(key) { case Canvas.KEY_NUM1: return KEY_NUM1_CHARS; case Canvas.KEY_NUM2: return KEY_NUM2_CHARS; case Canvas.KEY_NUM3: return KEY_NUM3_CHARS; case Canvas.KEY_NUM4: return KEY_NUM4_CHARS; case Canvas.KEY_NUM5: return KEY_NUM5_CHARS; case Canvas.KEY_NUM6: return KEY_NUM6_CHARS; case Canvas.KEY_NUM7: return KEY_NUM7_CHARS; case Canvas.KEY_NUM8: return KEY_NUM8_CHARS; case Canvas.KEY_NUM9: return KEY_NUM9_CHARS; case Canvas.KEY_NUM0: return KEY_NUM0_CHARS; } return null; } boolean isClearKey(int key) { return key =3D=3D -8; } void clearChar() { if(currentText.length() > 0 && caretIndex > 0) { caretIndex--; =
currentText.deleteCharAt(caretIndex); currentString =
=3D currentText.toString(); } } void updateCaretPosition() { caretLeft =3D inputFont.substringWidth(currentString, 0, caretIndex); if(caretLeft + inputTranslationX < 0) { inputTranslationX =3D - caretLeft; =
} else if(caretLeft + inputTranslationX > =
inputWidth) { inputTranslationX =3D =
inputWidth - caretLeft; } } public void keyPressed(int key) { int gameAction =3D getGameAction(key); System.out.println("KEY: =
" + key + ", " + =
gameAction); =
if(isClearKey(key)) { clearChar(); updateCaretPosition(); goToNextChar =3D true; } else if(key >=3D KEY_NUM0 && key <=3D =
KEY_NUM9) { writeKeyPressed(key); } else if(gameAction =3D=3D Canvas.LEFT) { if(caretIndex > 0) { caretIndex--; =
updateCaretPosition(); goToNextChar =
=3D true; } } else if(gameAction =3D=3D Canvas.RIGHT) { if(caretIndex < currentText.length()) { if(goToNextChar) caretIndex++; =
updateCaretPosition(); goToNextChar =
=3D true; } } } public void writeKeyPressed(int key) { if(goToNextChar || key !=3D lastPressedKey) { goToNextChar =3D true; lastPressedKey =
=3D key; currentKeyStep =3D 0; } else { currentKeyStep++; } char[] chars =3D getChars(key); if(chars !=3D null) { if(currentKeyStep >=3D chars.length) { currentKeyStep -=3D chars.length; } if(goToNextChar) { currentText.insert(caretIndex, chars[currentKeyStep]); caretIndex++; } else { currentText.setCharAt(caretIndex - 1, chars[currentKeyStep]); } currentString =3D currentText.toString(); updateCaretPosition(); lastKeyTimestamp =3D System.currentTimeMillis(); goToNextChar =3D false; } } public void checkTimestamps() { long currentTime =3D System.currentTimeMillis(); if(lastCaretBlink + caretBlinkDelay < =
currentTime) { caretBlinkOn =3D =
!caretBlinkOn; lastCaretBlink =3D currentTime; } if(!goToNextChar && lastKeyTimestamp + =
maxKeyDelay < currentTime) { goToNextChar =3D true; } } public void run() { while(true) =
{ =
checkTimestamps(); repaint(); try { synchronized(this) =
{ wait(50L); } } catch(Exception e) { e.printStackTrace(); } } } public void paint(Graphics g) { g.setFont(inputFont); g.setColor(0xffffff); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(0x000000); g.translate(inputTranslationX, 0); g.drawString(currentString, 0, 0, Graphics.LEFT | Graphics.TOP); if(caretBlinkOn && goToNextChar) { g.drawLine(caretLeft, 0, caretLeft, inputHeight); } g.translate(- inputTranslationX, 0); }}
that code in this site
I want to edit it and replace to but not appear
how to me do that
and about questions of petrib ,I dont know how to check the receiving device that it has a font that can actually disply that symbol/glyph properly
how to me do that???
I am new on the programming and i need help u