Java Append Key Input to String -


for current project need create custom text box gets each key pressed , adds string. i'm updating method retrieves key user pressing , add so:

public void addcharacter(string c) {     string before = text;     string after = before;      if (!before.endswith(c)) {      after = text + c;     } else {       //what can here check if key        //was released , pressed again,        //it adds character number of times user presses key.     }        text = after; } 

my problem if type key adds tons of them because of fact updating, why had check if it's same letter before, , not add it.

edit: example of how add key:

if (key.a) {    addcharacter("a");     return;  } 

i think can job done using keylistener. listener sends events each time key typed, pressed , released. in nutshell, listen keypressed event , not type letter until receive keyreleased event.


Comments

Popular posts from this blog

symfony - TEST environment only: The database schema is not in sync with the current mapping file -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -