Click to See Complete Forum and Search --> : How to use one dementional array with applet calculator?


earth
May 11th, 2000, 12:20 AM
How to use one demensional array with applet calculator? I try to add one dementional array and output it in the GUI. But when I display it, it won't display every number it just only display the last number. So, I wonder how to make it display all the numbers in the array? If any body know the answer, please, get back with me as soon as posible. Thank you.

Earth

dogbear
May 11th, 2000, 06:00 AM
Earth,

I don't quite understand the problem you're having with one dimensional arrays.
Could you give a code snippet to better help you with this problem?

Regards,
dogBear

earth
May 11th, 2000, 05:10 PM
I mean you actually declare arrays as

private double [] a = new double [10];
private double [] b = new double [10];
private double [] c = new double [10];
then you do

int i;
for (int i = 0; i < 10; i++){
c[i] = a[i] + b[i];(a,b,and c with square bracket)
textfield.setText(c[i]);}

I tried to put square bracket around the array variables but it sort of disapear when I preview the message

but when I did that the number that display is just show the last number but I want the textfiled to show all the numbers which is 10. Do you know how to get the array to output in the textfield all ten number? please get back with me with my problem. Thank you.

Earth

dogbear
May 12th, 2000, 05:57 AM
Earth,

I fully understand now...

Here's a solution:double[] a = new double[10];
double[] b = new double[10];
double[] c = new double[10];
for ( int index = 0 ; index < 10 ; index++ )
c = a[index]+b[index];
// here's where you write the outputs to a textfield...
for ( int index = 0 ; index < 10 ; index++ )
textField.setText(textField.getText() + c[index] + " " );

The problem you were probably facing was that when you setText() for a TextField or TextArea, you are setting it, not [i]appending to it. So the trick is to get the current text in the TextField and set it back into the TextField along with the new peice of text.

Hope that does the trick.

Regards,
[b]dogBear[b]

earth
May 12th, 2000, 05:00 PM
Thank you so much for solve my problem for me. I will try it and see but so far it did print out all ten number but now I have a different problem they are all the same so I have to see how can I get it to read the set of array and print out from the set that contain all the different number when you input them in. I don't know if you get what I said but if you don't please let me know and I will explain them to you. Thank you

Earth

earth
May 13th, 2000, 12:45 PM
I did what you suggest but when I did it print out the same text for 10 times. What I want to do is to get all different number in array A then get all 10 number for array B. So do you know how can get the number to store in the array because when I did that it print out the same number.

Please get back Thank you

Earth

dogbear
May 15th, 2000, 04:19 AM
Earth,

Sorry but I guess I don't understand.

Could you explain what you want to do again?
A)Are you having problems with storing input
from the user to the array?
B)What exactly do you want to print out?
C)Other problems?

Email me at: thedogbear@hotmail.com
It will be quicker.

Regards,
[b]dogBear[b]