English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

The class 'lucky_dip' has an array. In another class, 'Frame1', in the main method I need to read the results of the array and display in in jTextFields.

So the value at array position 0 to be displayed in jTextField1;
the value at array position 1 to be displayed in jTextField2;
etc

PLEASE HELP!

2007-07-26 03:49:10 · 5 answers · asked by Night_nurse 2 in Computers & Internet Programming & Design

5 answers

I'd recommend you collect your JTextField instances into a parallel array when you create them. Also add an accessor so that the GUI class (with the text fields) can access the array of lucky numbers. Then you'd have, say:

JTextField num_fields[6];
int lucky_nums[] = otherInstance.getNumberArray();

for (int i=0; i num_fields[i].setText("" + lucky_nums[i]);
}

2007-07-26 04:06:29 · answer #1 · answered by McFate 7 · 1 0

Either make the array a global variable that all classes can access or create a getter method that can return an individual element of the array.

2007-07-26 04:05:49 · answer #2 · answered by AnalProgrammer 7 · 0 0

Is the array in 'lucky_dip' static? If so, you can add a static method to 'lucky_dip', e.g.

public static int[] getArray() {
return name_of_array;
}

Then in class 'Frame1' you can get the array as follows:

int[] array = lucky_dip.getArray();

2007-07-26 04:17:34 · answer #3 · answered by garbanzosauced 2 · 0 0

Re:... the minimum and maximum numbers. You need two holding (storage) areas. (Variables.) One to hold the min value and one to hold the max value. When your program starts, initialize the min value with something like 9999999. Then, as the program reads each of the ten numbers, take a moment and compare that number to the current number in the min variable and that number to the current number in the max variable. If this current number read is LESS than the current min value, then THAT number becomes the NEW min variable. Move it in there. It will the first time thru. Recall we started it out with 9999999, so of course it will be lower. If this current number read is GREAT than the current max value, then THAT number becomes the NEW min variable. Move it in there. It will the first time thru. It will begin as 0. That's it. When all ten numbers are looked at and compared in this way, your min variable will contain the lowest number entered, and your max variable will contain the largest value entered.

2016-05-19 00:23:53 · answer #4 · answered by iva 3 · 0 0

try this>>>>


in main method write ::

lucky_dip ld = new lucky_dip();
/*
here "arrayname" is name of array u have
given in class lucky_dip ....
i'm assuming that u have string array
*/

jTextField1.setText(ld.arrayname[0].tostring());
jTextField2.setText(ld.arrayname[1].tostring());
jTextField3.setText(ld.arrayname[2].tostring());



try this if u need more help ..... i'm here

2007-07-26 04:24:42 · answer #5 · answered by Ashish_T 1 · 0 0

fedest.com, questions and answers