C
C
Conover2015-09-01 13:38:39
Java
Conover, 2015-09-01 13:38:39

How to properly bind buttons and JTextArea in Java?

I'm just learning to program in Java and trying to make a calculator, but there was a problem, I created a button and attached an event to it, when it is pressed, a character is added to the JTextArea. But when another character is entered, the previous one is deleted. How can I make it so that when I click the def. the symbol was added, but did not take its place?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Emin, 2015-09-01
@Conover

Elementary: every time you press the button, take the text from the field, add a new character to it and put it back in the same field.

String newText = field.getText() + "a";
field.setText(newText);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question