Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
domanik
domanik's Profile
1
Posts
1
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Problem with keyPressed
[2 Replies]
08-Dec-2011 12:47 PM
Forum:
Programming Questions
Hi can anyone help with this?
I'm trying to avoid repeating code unnecessarily, so I'm creating a function:
void cursorSet(String cut, String empty, int cutLength, Textfield t)
{
int cut = empty.substring(0, empty.length() - 1);
int cutLength = cut.length();
if ( cutLength < 1 ) cut = " ";
if ( t.isFocus() && keyCode != SHIFT )
{
if ( key != BACKSPACE && keyCode != RIGHT && key != TAB ) empty = empty + " ";
if ( key == BACKSPACE || keyCode == LEFT ) empty = cut;
if ( keyCode == RIGHT && empty.length() < t.getText().length() ) empty = empty + " ";
if ( empty.length() == t.getText().length() && keyCode != LEFT) empty = cut + " ";
}
}
I want to call this multiple times from keyPressed() like so:
cursorSet(cut1, empty1, cutLength1, t1);
cursorSet(cut2, empty2, cutLength2, t2);
cursorSet(cut3, empty3, cutLength3, t3);
The code within cursorSet() works perfectly in keyPressed(), yet calling it as a method (as above) doesn't do anything.
It's the same code! why doesn't it work? I don't want to have to explicitly write the same code 15 times!
«Prev
Next »
Moderate user : domanik
Forum