-1

Here is my code to calculate and show them to a label by button press I want to know is there a way to make it automatic...

int one =Integer.parseInt(value_1.getText());
int two =Integer.parseInt(value_2.getText());
int three =Integer.parseInt(value_3.getText());

String answer = String.valueOf(one+two+three);

lbltotal.setText(answer);
Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
  • add an event to keypress/onchange on value_1, value_2, value_3 to fire off a function which does what you have above. Can't remember off the top of my head what that event is in Java, I'll look. JTextField? Have you tried https://stackoverflow.com/questions/3953208/value-change-listener-to-jtextfield ? – Robert Apr 09 '18 at 18:09
  • Please accept the answer which helped you most in solving your problem. It helps future readers. If the answers weren't helpful leave comments below them. So the poster can update them accordingly. – Roshana Pitigala Sep 23 '18 at 18:50

1 Answers1

0

On Properties >> Events panel select keyReleased and enter your code there.

private void value_1KeyReleased(java.awt.event.KeyEvent evt) {
     // TODO add your handling code here:
}

enter image description here

Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80