Results 1 to 4 of 4
Thread: calculations on text box inputs
- 03-07-2014, 12:11 AM #1
Member
- Join Date
- Feb 2014
- Posts
- 20
- Rep Power
- 0
calculations on text box inputs
Hi guys,
I have made a simple form, it consists of 3 text box's textbox1, textbox2 and textbox3 as well as 1 button button1. What I want to be able to do is put numbers into textbox 1 and 2 and then show the multiplication of these numbers in textbox 3 when the button is pressed and I was wondering what is the standard way of reading these numbers from the text box and allowing us to do the conversion obviously in the textbox its a string and we need to convert to an int or double or whatever to be able to perform calculations on them then convert it back into a string to display in text box 3?
Any help would be greatly appreciated. Thanks.Last edited by Dark Knight; 03-07-2014 at 12:16 AM.
- 03-07-2014, 12:31 AM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: calculations on text box inputs
You don't read the numbers. They are just typed in the text box (I assume JTextField). They can be retrieved with the getText() method.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 03-07-2014, 12:38 AM #3
Member
- Join Date
- Feb 2014
- Posts
- 20
- Rep Power
- 0
Re: calculations on text box inputs
Thanks for the input but I cant do textBox3.setText(textBox1.getText() * textBox2.getText());
- 03-07-2014, 12:58 AM #4
Senior Member
- Join Date
- Jan 2013
- Posts
- 168
- Rep Power
- 9
Re: calculations on text box inputs
The thing that you need to do is convert those both into numbers(ints, doubles, floats, longs). When you use the getText() method it returns a String which you can not use operators on. You need to convert the two Strings to numbers, multiply them and then set the text to that number in String form.
So what you could do is:
Java Code:textbox3.setText("" + (Integer.parseInt(textBox1.getText()) * Integer.parseInt(textBox2.getText())));
Last edited by pj6444; 03-07-2014 at 01:03 AM. Reason: Adding example code
Similar Threads
-
Counting positive number inputs and negative number inputs of user. HELP!
By cs3 in forum New To JavaReplies: 1Last Post: 10-24-2012, 01:21 PM -
get three inputs at one time, then perform the conversions on the three inputs!
By niloufar in forum New To JavaReplies: 3Last Post: 09-06-2012, 06:30 PM -
OO for calculations?
By StateMachine in forum New To JavaReplies: 1Last Post: 12-31-2011, 09:17 AM -
update text output (eg. jLabel) during calculations
By kosmo76 in forum AWT / SwingReplies: 2Last Post: 04-06-2011, 11:30 PM -
decimal calculations?
By arnab321 in forum CLDC and MIDPReplies: 5Last Post: 11-19-2008, 04:36 AM
Bookmarks