asd32
asd32

Reputation: 45

netbeans how to take from two textfields the fixed values and add them to a third with buttons?

/*code inside of 1st button*/
private void btn1......{
double a1,a2,result;

a1=Double.parseDouble(jTextField1.getText());
a2=Double.parseDouble(jTextField2.getText());

result=a1+a2;

jTextField3.setText(String.valueOf(result));}

/*code inside of 2nd button*/
private void btn2......{
double a1,a2,result;

a1=Double.parseDouble(jTextField4.getText());
a2=Double.parseDouble(jTextField5.getText());

result=a1+a2;

jTextField6.setText(String.valueOf(result));}

/*code inside of 3rd button*/
private void btn3......{
double a1,a2,result;

a1=Double.parseDouble(jTextField3.getText());
a2=Double.parseDouble(jTextField6.getText());

result=a1+a2;

jTextField7.setText(String.valueOf(result));}

So i am adding 2 numbers with the first button and another two with the second button and i want with a third button to take the sum of them but when i click on 3rd button doesn't show anything on textfield why?

Upvotes: 1

Views: 3228

Answers (2)

aashima
aashima

Reputation: 1203

why do u have a '.' operator after parseDouble? a2=Double.parseDouble.(jTextField2.getText());

Correcting that would help.. gud luck

Upvotes: 3

Savva Pouroullis
Savva Pouroullis

Reputation: 46

I find that using Double.valueOf(String str) works smoother. Perhaps try that. Then when you put it into a field as text, just field.setText("" + doubleNum);

Of course, this will all go to the dogs if the values in the text fields are not actually numbers... so perhaps add some error checking for that?

Upvotes: 2

Related Questions