开发者

addition between two jtextfield

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:

  1. Addition :

    int result = Integer.valueOf(jTextField1.getText()) + Integer.valueOf(jtextField2.getText());

  2. Multiplication :

    int result = Integer.valueOf(jtextField1.getText()) * Integer.valueOf(jtextField.getText());

Note : Use Double.valueOf() if the values are floating point literals.


  1. Get values of both jtextfield.

  2. Use Integer.parseInt or Double.parseDouble depending on your data type .

  3. Now you will have those value in int/double. you can use any maths operator on them.

    • , *
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜