I have a problem with the following:
I want to add the java开发者_如何学运维.lang.String
values of two JTextfields
together.
How can I convert the data in such a manner that this is possible?
Try the following:
Addition :
int result = Integer.valueOf(jTextField1.getText()) + Integer.valueOf(jtextField2.getText());
Multiplication :
int result = Integer.valueOf(jtextField1.getText()) * Integer.valueOf(jtextField.getText());
Note : Use Double.valueOf()
if the values are floating point literals.
Get values of both jtextfield.
Use Integer.parseInt or Double.parseDouble depending on your data type .
Now you will have those value in int/double. you can use any maths operator on them.
- , *
精彩评论