×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Regular Contributor
    Join Date
    Aug 2009
    Location
    Iran - Tabriz
    Posts
    111

    make textbox in canvas

    Hi , i want to make textbox in canvas to give some data from user. i use this code , but i have probleam in change between to textbox , whene i press DOWN or UP my text move too !!!,please help me to modify this code
    tanks
    Code:
    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;
           }
    
        }

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: make textbox in canvas

    Quote Originally Posted by mahdi68 View Post
    Hi , i want to make textbox in canvas to give some data from user. i use this code , but i have probleam in change between to textbox , whene i press DOWN or UP my text move too !!!,please help me to modify this code
    tanks
    Code:
    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{
               if(currentY==110)key();
               else key1();
           }
           repaint();
           }
    
    public String key1(){
    
           if(keyName.equals("0")){
            bufferText = "0";
            text2 = (text2.length()>=23)?( text2) :( text2+ bufferText);
           }
           else if(keyName.equals("1")){
               bufferText = "1";
           text2 = (text2.length()>=23)?( text2) :( text2+ bufferText);
           }
           else if(keyName.equals("2")){
               bufferText = "2";
               text2 = (text2.length()>=23)?( text2) :( text2+ bufferText);
           }
           else if(keyName.equals("3")){
               bufferText = "3";
               text2 = (text2.length()>=23)?( text2) :( text2+ bufferText);
           }
           else if(keyName.equals("4")){
               bufferText = "4";
               text2 = (text2.length()>=23)?( text2) :( text2+ bufferText);
           }
           else if(keyName.equals("5")){
               bufferText = "5";
               text2 = (text2.length()>=23)?( text2) :( text2+ bufferText);
           }
           else if(keyName.equals("6")){
               bufferText = "6";
               text2 = (text2.length()>=23)?( text2) :( text2+ bufferText);
           }
           else if(keyName.equals("7")){
               bufferText = "7";
               text2 = (text2.length()>=23)?( text2) :( text2+ bufferText);
           }
           else if(keyName.equals("8")){
               bufferText = "8";
               text2 = (text2.length()>=23)?( text2) :( text2+ bufferText);
           }
           else if(keyName.equals("9")){
               bufferText = "9";
               text2 = (text2.length()>=23)?( text2) :( text2+ bufferText);
           }
         //  else if (keyName.equals("DOWN")){
          //     currentX=15;
         //      currentY=110;
        //   }
         //  else if(keyName.equals("UP")){
         //        currentX = 15;
         //        currentY = 45;
         //  }
           else{
               text2 = keyName;
           }
               return text2;
           }
    
    
    
      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;
           }
    
        }

    Try the changes above in BOLD.


    thanks,
    ~Amitabh
    (Poster of the Month -Aug'09)
    Follow me on my blog for Innovative Mobile Apps

  3. #3
    Regular Contributor
    Join Date
    Aug 2009
    Location
    Iran - Tabriz
    Posts
    111

    Re: make textbox in canvas

    Hi,i try your change but it`s not sloved my probleam , please run this code to see what is probleam
    tanks

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: make textbox in canvas

    Please refer to http://wiki.forum.nokia.com/index.ph...put_in_Java_ME
    and see if this example can help you.

    Otherwise use LWUIT Textfield

    thanks,
    ~Amitabh
    (Poster of the Month -Aug'09)
    Follow me on my blog for Innovative Mobile Apps

  5. #5
    Nokia Developer Champion
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: make textbox in canvas

    thanks,
    jitu_goldie..

    KEEP TRYING..

  6. #6
    Regular Contributor
    Join Date
    Aug 2009
    Location
    Iran - Tabriz
    Posts
    111

    Re: make textbox in canvas

    Hi , i checked links but thats not sloved my probleam !!! after completing textbox1 i press Down to move second textbox but text of first textbox move too !!!

  7. #7
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: make textbox in canvas

    Give your final code after you did my correction, because one variable is text & other is text2. So how it can be printed at both the places.

    thanks,
    ~Amitabh
    (Poster of the Month -Aug'09)
    Follow me on my blog for Innovative Mobile Apps

  8. #8
    Regular Contributor
    Join Date
    Aug 2009
    Location
    Iran - Tabriz
    Posts
    111

    Re: make textbox in canvas

    after run when i click a key no thing displayed but whene i press DOWN and press key text shown in second textbox and whene presses UP text moved to first textbox !!!


    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{
    if(currentY==110)key();
    else key1();
    }
    repaint();
    }

    public String key1(){

    if(keyName.equals("0")){
    bufferText = "0";
    text2 = (text2.length()>=23)?( text2) text2+ bufferText);
    }
    else if(keyName.equals("1")){
    bufferText = "1";
    text2 = (text2.length()>=23)?( text2) text2+ bufferText);
    }
    else if(keyName.equals("2")){
    bufferText = "2";
    text2 = (text2.length()>=23)?( text2) text2+ bufferText);
    }
    else if(keyName.equals("3")){
    bufferText = "3";
    text2 = (text2.length()>=23)?( text2) text2+ bufferText);
    }
    else if(keyName.equals("4")){
    bufferText = "4";
    text2 = (text2.length()>=23)?( text2) text2+ bufferText);
    }
    else if(keyName.equals("5")){
    bufferText = "5";
    text2 = (text2.length()>=23)?( text2) text2+ bufferText);
    }
    else if(keyName.equals("6")){
    bufferText = "6";
    text2 = (text2.length()>=23)?( text2) text2+ bufferText);
    }
    else if(keyName.equals("7")){
    bufferText = "7";
    text2 = (text2.length()>=23)?( text2) text2+ bufferText);
    }
    else if(keyName.equals("8")){
    bufferText = "8";
    text2 = (text2.length()>=23)?( text2) text2+ bufferText);
    }
    else if(keyName.equals("9")){
    bufferText = "9";
    text2 = (text2.length()>=23)?( text2) text2+ bufferText);
    }
    // else if (keyName.equals("DOWN")){
    // currentX=15;
    // currentY=110;
    // }
    // else if(keyName.equals("UP")){
    // currentX = 15;
    // currentY = 45;
    // }
    else{
    text2 = keyName;
    }
    return text2;
    }



    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;
    }

    }

Similar Threads

  1. Build Error on Carbide
    By deepak_pious in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 3
    Last Post: 2010-05-23, 09:37
  2. How to make the background of a Custom Canvas Transparent
    By markchua_99 in forum Mobile Java General
    Replies: 4
    Last Post: 2008-09-30, 02:57
  3. Cannot run command line GCCE HelloWorldBasic on Emulator
    By loginssuck in forum Symbian Tools & SDKs
    Replies: 33
    Last Post: 2008-06-21, 12:58
  4. Strange problem with compilation!!! ARM9E
    By dmazgalin in forum Symbian
    Replies: 1
    Last Post: 2007-11-02, 09:33

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •