Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to shift a String in a rectangle which is type of Canvas

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation How to shift a String in a rectangle which is type of Canvas

    Hi,
    I had create a rectangle in Canvas like the textfield and now I can print my input in that rectangle, I want that how can I write the input when it's size is bigger than the rectangle! I want that when it's size is bigger than the rectangle the remain of my input must be shown and the input which I wrote earlier must be shifted! actualy I want to scroll my input in the rctangle, How can I do it? Could anyone show me sample code for it please?
    to scrolling the input in the rectangle I worte some code like below but when i scroll the input with Canvas.Right the String which I inserted after scrolling will be seprated to characters! Could you help me to solve it please?How could I shift the String when I click on Canvas.Right?

    public void copyStr(){
     
    tchar=this.text.toCharArray();
    copy=text.length()-1;
    textchar[cp]=tchar[copy];
    t[p]=textchar[cp];
    cp++;
    p++;
    if(text.length()>=9){
     
    shiftRight();
     
    }
    }
    public void shiftRight(){
    int m=0;
    String temp;
    char []te;
    for (int i=10;i<this.text.length()-1;i++){
    t[i-1]=t[i];
    }
    for(int i=10;i<this.text.length()-1;i++){
    textchar[m]=t[i];
    m++;
    }
    text=new String(textchar);
    }
     
    protected void keyPressed(int keyCode)
    {
    if(keyCode==-4){
    shiftRight();
    }
     
    long currentTime = System.currentTimeMillis();
    int pressedKeyNum = getNum(keyCode);
    if( pressedKeyNum >= 0 && pressedKeyNum <= 9 ) {
    if(keyCode == this.lastKeyStroke && currentTime - this.lastKeyStrokeTime < MIN_STROKE_TIME)
    {
    cursorplace++;
    cursor[cursorplace]='_';
    this.text = this.text.substring(0, this.text.length() - 1);
    this.text += KEY_MAP[pressedKeyNum][this.lastKeyStrokeIndex];
    this.lastKeyStrokeIndex++;
    copyStr();
    }
     
    else
    {
    this.text += KEY_MAP[pressedKeyNum][0];
    this.lastKeyStrokeIndex = 1;
    copyStr();
    }
     
    if(this.lastKeyStrokeIndex >= KEY_MAP[pressedKeyNum].length)
    {
    this.lastKeyStrokeIndex = 0;
    }
    else
    {
    if( pressedKeyNum == 10 ) {
    this.remove();
    }
    }
    this.lastKeyStroke = keyCode;
    this.lastKeyStrokeTime = System.currentTimeMillis();
    }
     
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How to shift a String in a rectangle which is type of Canvas

    This thread has been cross posted here:

    http://www.java-forums.org/cldc-midp/41815-how-shift-string-rectangle-type-canvas.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting
    http://www.javaprogrammingforums.com...s-posting.html

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. How to get scores from user in Canvas J2ME?
    By elenora in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: April 4th, 2011, 04:10 AM
  2. Need something like a "Hashtable<String[], Integer>" kind of data type @@
    By Albretch Mueller in forum Java Theory & Questions
    Replies: 2
    Last Post: November 27th, 2010, 10:24 PM
  3. make textbox in canvas
    By mahdi in forum Java ME (Mobile Edition)
    Replies: 2
    Last Post: October 6th, 2009, 07:10 AM
  4. he operator / is undefined for the argument type(s) String, int
    By mtbr00x in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: September 8th, 2009, 08:34 PM
  5. Dropping to graphic element dragged from JList
    By tua1 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 29th, 2008, 08:22 AM