-1

After storing the string into nick I want to print the string, but when I print string it only prints the last character, not whole string. How do I print the whole string?

Michael Shopsin
  • 2,055
  • 2
  • 24
  • 43
  • 2
    Could you please share some of your code so we can help with your problem? – Michael Shopsin Oct 29 '19 at 18:02
  • Hi, and welcome to SO. For everyone else to understand and be able to help you, please consider editing your question. You could start by reading this article: [How do I ask a good question](https://stackoverflow.com/help/how-to-ask) and try reformulating the question. It will help others reproduce the problem and maybe find an answer. – pimarc Oct 29 '19 at 19:28

1 Answers1

0

you need to use a StringBuilder (or reuse the String nick if performance is not an issue [not encouraged but simpler]), and append the key generated in each keystroke. What you are currently doing is overwriting each previous keystroke when you store it to the string nick.

public void keyReleased(KeyEvent e) { }
public void keyTyped(KeyEvent e) {
    c = e.getKeyChar();
    nick+=Character.toString(c); //string
    nick.append(c); // StringBuilder


}
David Kabii
  • 642
  • 6
  • 17