import java.util.*;
import java.text.*;
import javax.swing.*;
class Lab4Part2{
   public static void main (String[] args) {
		String ex1;
		Double num, F;
		final int a=0, b=0;
		JFrame myWindow=new JFrame();
		myWindow.setSize(500,400);
		myWindow.setTitle("Calculator");
		myWindow.setVisible(true);
		myWindow.setLocation(600,200);
		ex1=JOptionPane.showInputDialog(myWindow, "Enter an expression");
	        F=Double.parseDouble(ex1);
		num=(a+b);
		JOptionPane.showMessageDialog(myWindow, "The sum is "+num);
	}
}

I need some help I keep getting an error when I try to run it on JGrasp. I have no clue what I'm doing wrong and for that matter I don't know what I have to do next if I am doing something wrong or not. However I'm trying to create a program where there are one input dialog that asking for the expression in "a+b" form like I would have to input "1+2" and then the second dialog would be a message giving the answer to that 1+2 which would show the message of 3. Thanks for helping.

PS. I believe the Double.parseDouble is a wrong method in solving this issue and I believe I need to stack but I don't know how.

Update. I have also tried this:

import java.util.*;
import java.text.*;
import javax.swing.*;
class Lab4Part2{
   public static void main (String[] args) {
		Scanner scanner=new Scanner(System.in);
		String ex1;
		double num, F;
		int a=0, b=0;
		JFrame myWindow=new JFrame();
		myWindow.setSize(500,400);
		myWindow.setTitle("Calculator");
		myWindow.setVisible(true);
		myWindow.setLocation(600,200);
		ex1=JOptionPane.showInputDialog(myWindow, "Enter an expression");
	        F=Double.parseDouble(ex1);
		a=scanner.nextDouble();
		b=scanner.nextDouble();
		num=(a+b);
		JOptionPane.showMessageDialog(myWindow, "The sum is "+num);
	}
}

However this hasn't worked either unfortunately.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.