Results 1 to 2 of 2
- 04-04-2011, 10:05 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 30
- Rep Power
- 0
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();
}
}
- 04-04-2011, 01:24 PM #2
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
Error: "The method startsWith(String, String) is undefined for the type StringUtils"
By shihad_s in forum New To JavaReplies: 10Last Post: 12-07-2010, 12:29 PM -
Open type (Ctrl-Shift-T) does not find types
By Zhenya_Merom in forum EclipseReplies: 2Last Post: 11-04-2009, 10:15 AM -
Draw String in Rectangle
By DavidG24 in forum AWT / SwingReplies: 3Last Post: 05-20-2009, 07:05 AM -
Confused beginner with Rectangle type question
By sigssoft in forum New To JavaReplies: 2Last Post: 10-08-2008, 02:56 AM -
[SOLVED] Cast string type to int type
By GilaMonster in forum New To JavaReplies: 9Last Post: 09-17-2008, 10:43 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks