Results 1 to 2 of 2
  1. #1
    elenora is offline Member
    Join Date
    Apr 2011
    Posts
    30
    Rep Power
    0

    Question 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?:o


    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
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

Similar Threads

  1. Replies: 10
    Last Post: 12-07-2010, 12:29 PM
  2. Open type (Ctrl-Shift-T) does not find types
    By Zhenya_Merom in forum Eclipse
    Replies: 2
    Last Post: 11-04-2009, 10:15 AM
  3. Draw String in Rectangle
    By DavidG24 in forum AWT / Swing
    Replies: 3
    Last Post: 05-20-2009, 07:05 AM
  4. Confused beginner with Rectangle type question
    By sigssoft in forum New To Java
    Replies: 2
    Last Post: 10-08-2008, 02:56 AM
  5. [SOLVED] Cast string type to int type
    By GilaMonster in forum New To Java
    Replies: 9
    Last Post: 09-17-2008, 10:43 AM

Posting Permissions

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