How to create an Int or double of what the user types int a JTextField?
I am not sure if this is the correct thread but it is what I believe is the closest to my question.
--I am making a simple calculator and I need to make a double variable (or Int) that remembers what the user types inside the JTextField. How can I do this?
Re: How to create an Int or double of what the user types int a JTextField?
You need to extract the text from the JTextField *when* you need it by calling getText() on the field, and then convert it to double or int (as the need may be) by using the double Double.parseDouble(String text) or int Integer.parseInt(String text) as the need may be.
Re: How to create an Int or double of what the user types int a JTextField?
You might find it easiest to write your own class that has fields for both the string that the user entered and the int or double value it represents.
It depends somewhat on what exactly you are trying to do. A simple calculator could get by with knowing the string (the sequence of digits) the user entered and, at some point, simply discard that information and replace it with a numerical value. In that case defining ypur own type (class) would be unnecessary.