How To Make A Addition Calculator In Java Using JOption

How To Make A Addition Calculator In Java Using JOption
Okay guys today i will be teaching you how to make a simple addition calculator using Joption in java, I saw someone wrote some codes to calculate addition also it uses Java Scanner. This is that program .
import java.util.Scanner;

class basic_cal
{
  public static void main(String args[])
  {
   Scanner shim = new Scanner(System.in);
   double first_number,second_number,answer;
   System.out.println("Enter First Number : ");
   first_number = shim.nextDouble();
   System.out.println("Enter Second Number : ");
   second_number = shim.nextDouble();
   answer = first_number + second_number;
   System.out.println("Answer : " + answer);
   }
}   
Okay now i saw that and got an idea to make the same thing with Joption , Joption is like the messagebox we have in c# and vb.net ok , this is the program i wrote :
import javax.swing.JOptionPane;

/** 
 * Author : Mohamed Shimran
 * Blog : http://www.ultimateprogrammingtutorials.blogspot.com
 */
 
class Shim_X
{
public static void main(String args[])
{

 String shim = JOptionPane.showInputDialog("First Number ?");
 String shim2 = JOptionPane.showInputDialog("Second Number ?");
 
 int number1 = Integer.parseInt(shim);
 int number2 = Integer.parseInt(shim2);
 int sum = number1 + number2;
 
 JOptionPane.showMessageDialog(null, "Answer Is : " + sum, "Answer", JOptionPane.PLAIN_MESSAGE);
 
 }
 
}
The exceptions are not handled because I am not that good in java to handle exceptions :D , if you run this program you will be asked for the first number then you will be asked for the second number and at last you will get the answer.
How To Make A Addition Calculator In Java Using JOption
Enter First Number

How To Make A Addition Calculator In Java Using JOption
Enter Second Number

How To Make A Addition Calculator In Java Using JOption
the answer
enjoy !

1 comments:

hai it s nice :-b

Reply

Post a Comment