Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to Store JTextField Values in the Array

Zulfi KhanAug 26 2015 — edited Aug 30 2015

Hi,

I am trying to write a code to store JTextField values in an array.I know how to convert JtextField in to integer. But after that we have different integer variables. I cant figure out how to store values of these different integer variables into an array using a loop.

public class ArrAvg{

public static void main(String[ ] args) {

  int arr[10] = new int[10];

  inputNumbers(arr);

 

}

void int inputNumbers(int arr[10]) {

  int i;

  JTextField field1 = new JTextField();

  JTextField field2 = new JTextField();

  JTextField field3 = new JTextField();

  String value1 = field1.getText();

  String value2 = field2.getText();

  String value3 = field3.getText();

  val1 = Integer.parseInt(value1);

  val2 = Integer.parseInt(value2);

  val3 = Integer.parseInt(value3);

  for(i=0; i<10; ++i) {

    arr[i] = val1 (this should be replaced by val2 and after that by val3 ?????????? i dont know how to do this)

}

}

Some body please guide me.

Zulfi.

This post has been answered by unknown-7404 on Aug 28 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 27 2015
Added on Aug 26 2015
7 comments
5,383 views