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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -