I've tried this and i'm back to how i was before. It would add each entered value and straight after show it. So I input 2, it shows me 2, i input another 2, it shows me 4, i input 4, it shows me 8, i input 12, it shows me 20. It will keep doing that showing a dialog box requesting input with OK and Cancel then when i hit OK the show dialog box with the total amount and an OK button.
Here is the code, much simpler but i'm still unsure how to make it only show the total when Cancel is hit:
Java Code:
import javax.swing.JOptionPane;
public class testing
{
public static void main (String[] args)
{
double total = 0.0;
String valueInput = "";
while (valueInput != null)
{
valueInput = JOptionPane.showInputDialog("Enter a value:");
if (valueInput != null)
{
double numInput = Double.parseDouble(valueInput);
total = total + numInput;
}
JOptionPane.showMessageDialog(null, "£" + total);
}
}
}
Bookmarks