Link to home
Start Free TrialLog in
Avatar of wesmk
wesmk

asked on

Java Applet with arrays

I'm trying to get real numbers entered from user (max 20) and put them in an array to sort ascending and descending also to find the mean, median, and range.  I know how to do all that, I just can't figure out how to put the numbers entered into the array.  thanks for any help

Wesmk
Avatar of Peter Kwan
Peter Kwan
Flag of Hong Kong image

Which kinds of user interface below does your application fit?

a) java YourApp 1 2 3 ...
b) java YourApp
Enter numbers: 1 2 3
c) GUI based, that means you have used AWT (or Swing) to handle user's input?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oops, sorry I overlook the title.

I assume you are using TextField (or JTextField) to allow users to enter the numbers. (Please correct me if i am wrong.)

Then the following code may help to solve your problem:

TextField userInputField = new TextField();
String numbers = userInputField.getText();
StringTokenizer tokens = new StringTokenizer(numbers);
float numbersArray[20];
int i=0;
while (tokens.hasMoreTokens())
    numbersArray[i] = Float.parseFloat(tokens.nextToken());

Hope this helps.
OOOOOOOOOOOoooooooooopppppppppppppppps!! I overlooked the title too! But hope my code helps you, man! You can just put a few modifications like instead of br.readLine (), read it from the text-field as myTextField.getText (). Keep one text-field and a submit button. Enter the value in the text-field and then click the button. When the button is pressed (in the actionPerformed () method), read the value from the text-field as I've told.

Mayank.
I see that you've posted this question again on the 12th. I've sent you a code-fragment there.

https://www.experts-exchange.com/questions/20548427/Java-Applet-with-arrays.html

Mayank.
Avatar of CleanupPing
CleanupPing

wesmk:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points to mayankeagle

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
Please go ahead with that recommendation.