Blog » JAVA » how to create Java number addition

how to create Java number addition

This Article will show you how to creating java number addition. when you add two Integers numbers in java. after addition results displays on the screen. This simple script learn.

Example: Program to Add Two Integers

 private void addActionPerformed(java.awt.event.ActionEvent evt) {
    double n1 = Double.parseDouble(txtn1.getText());
    double n2= Double.parseDouble(txtn2.getText());
    double result = n1 + n2;
    txtn3.setText(String.valueOf(result)); 
  }


/* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
        new NumberAddition().setVisible(true);
      }


finally display when you run the program : output
Enter two numbers: 50 30
The sum is: 80


we can use this script to clearing text numbers.


private void clearActionPerformed(java.awt.event.ActionEvent evt) {
  txtn1.setText(null);
  txtn2.setText(null);
  txtn3.setText(null);   
  }


You can download complete source code

ARTICLE POSTED BY : Admin

Hi, I'am k.g uththara. I'm a professional web developer. I write blog posts in my free time. if you want to contact me, send a message on contact page, thanks.