How to use one dementional array with applet calculator?
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
[384 byte] By [
earth] at [2007-11-15 20:12:55]

# 1 Re: How to use one dementional array with applet calculator?
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
# 2 Re: How to use one dementional array with applet calculator?
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
earth at 2007-11-10 2:54:43 >

# 3 Re: How to use one dementional array with applet calculator?
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]
# 4 Re: How to use one dementional array with applet calculator?
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 at 2007-11-10 2:56:38 >

# 5 Re: How to use one dementional array with applet calculator?
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
earth at 2007-11-10 2:57:38 >

# 6 Re: How to use one dementional array with applet calculator?
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]