import javax.microedition.lcdui.*;
public class MIDPCanvas extends Canvas {
String keyName,bufferText,text2,text="";
int currentX = 15;
int currentY = 45;
MIDPCanvas(){
setFullScreenMode(true);
}
protected void paint(Graphics g) {
g.setColor(211,211,211);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0,0,0);
g.drawString(" Price", 113, 15, Graphics.TOP | Graphics.HCENTER);
g.setColor(255,255,255);
g.fillRect(10, 30, 218, 40);
g.setColor(0);
g.drawString("Magsad", 100, 80, 0);
g.setColor(255,255,255);
g.fillRect(10, 100, 218, 40);
g.setColor(0,0,0);
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE));
g.drawString(text, currentX, currentY,0);
g.drawString(text2,15,110,0);
}
protected void keyPressed(int keyCode){
keyName = getKeyName(keyCode);
if (keyName.equals("DOWN")){
currentX=15;
currentY=110;
}
else if(keyName.equals("UP")){
currentX = 15;
currentY = 45;
}
else{
key();
}
repaint();
}
public String key(){
if(keyName.equals("0")){
bufferText = "0";
text = (text.length()>=23)?( text) :( text + bufferText);
}
else if(keyName.equals("1")){
bufferText = "1";
text = (text.length()>=23)?( text) :( text + bufferText);
}
else if(keyName.equals("2")){
bufferText = "2";
text = (text.length()>=23)?( text) :( text + bufferText);
}
else if(keyName.equals("3")){
bufferText = "3";
text = (text.length()>=23)?( text) :( text + bufferText);
}
else if(keyName.equals("4")){
bufferText = "4";
text = (text.length()>=23)?( text) :( text + bufferText);
}
else if(keyName.equals("5")){
bufferText = "5";
text = (text.length()>=23)?( text) :( text + bufferText);
}
else if(keyName.equals("6")){
bufferText = "6";
text = (text.length()>=23)?( text) :( text + bufferText);
}
else if(keyName.equals("7")){
bufferText = "7";
text = (text.length()>=23)?( text) :( text + bufferText);
}
else if(keyName.equals("8")){
bufferText = "8";
text = (text.length()>=23)?( text) :( text + bufferText);
}
else if(keyName.equals("9")){
bufferText = "9";
text = (text.length()>=23)?( text) :( text + bufferText);
}
// else if (keyName.equals("DOWN")){
// currentX=15;
// currentY=110;
// }
// else if(keyName.equals("UP")){
// currentX = 15;
// currentY = 45;
// }
else{
text = keyName;
}
return text;
}
}