2 dim array of textField

Hi
i have a 2 dim array of textField and i want to fill it with some data
for example:(this is a part of my applet)
public void inti()
            Panel table_panel;
            TextField[] [] table1 = new TextField[5][3];
            table_panel = new Panel();
            table_panel.setLayout(new GridLayout(5,3));
            for(int i = 0; i <5; i++)               // for each row
                 for(int j = 0; j < 3 ; j++)       // for each coloum
                 table1[i] [j]= new TextField(); 
                         table_panel.add(table1[i][j]);
                 }// end for
            ClassType obj  ;
            ClassType obj  = new ClassType(x,y);
            table1= obj.fillData();       
class ClassType{
                       //constructor...........
         public TextField[][] fillData()
          TextField[][] table= new TextField[5][3];
          String s = new String("A");
          for(int i = 0 ; i < 5 ; ++i)
              for(int j = 0; j<3 ; ++j)
               table[i][j] = new TextField(s);
          return table;
}The problem here is:
the applet is not intialized,should i dispaly table1 again after fillData
Thanks for you help

Thanks !
This is my applet again:
public void inti()
            Panel table_panel;
            TextField[] [] table1 = new TextField[5][3];
            table_panel = new Panel();
            table_panel.setLayout(new GridLayout(5,3));
            for(int i = 0; i <5; i++)               // for each row
                 for(int j = 0; j < 3 ; j++)       // for each coloum
                 table1[i] [j]= new TextField(); 
                         table_panel.add(table1[i][j]);
                 }// end for
            ClassType obj  ;
            ClassType obj  = new ClassType(x,y);
            table1= obj.fillData();       
class ClassType{
                       //constructor...........
         public TextField[][] fillData()
          TextField[][] table= new TextField[5][3];
          String s = new String("A");
          for(int i = 0 ; i < 5 ; ++i)
              for(int j = 0; j<3 ; ++j)
               table[i][j] = new TextField(s);
          return table;
}

Similar Messages

  • Event Handling in an Array of TextField

    I have created an array of textfields (say t[0],t[1],t[2],....) and want to implement the FocusListener Interface.
    I want to use the method focusLost() to get the name of the textfield in the form t[x] whenever the event occurs in the field.
    Can I do it? if yes, how?
    p.s.- getting back the array index is most important.

    I think it's possible.
    Extend the TextField class. Add 2 new methods, setID() and getID() and a new int field named ID. Change your code so that the array of TextFields is an array of your new class. When you construct the class, set the value of ID to be the same as the index.
    In the focusLost() method, use getSource() of the FocusEvent to get the Object that generated the event and cast that Object to the new class. Use the getID() method to get the index.
    I can think of other ways that use a similar approach.
    A different approach would not require extending TextField. Use getSource() to get a reference to the textfield and loop thru the textfield array comparing the reference to the array element until you have a match.

  • System.arraycopy (2 dim array) and growth of 2 dim array

    Hi everybody
    I am working on a program which contains a module that can perform Cartesian product on number of sets.
    The code I have developed so far is :
    import java.lang.reflect.Array;
    public class Cart5 {
    public static void main(String[] args) throws Exception
    int pubnewlength;
    // declare SolArray
    int[][] solArray;
    // initialize solArray
    solArray=new int[1][4];
    // Use for method
    for (int ii=0 ; ii<4 ; ii++)
    solver(solArray,ii);
    // Print the array ?
    System.out.println("\n  The array was changed ... " );
    }  // End main
    public void solver(int Solarray2[][] , int abi)
    int[][]  A  =  {  {1,2,3,5},
                      {4,6,7},
                      {11,22,9,10},
                      {17,33}
      jointwoArrays(solarray2,A,abi);
    // some other operations
    } // End Solver method
    public void jointwoArrays(int solarray3[][] , int aArray[][],int indexA)
    int y,u;
    int[][] tempArray;
    // calculate growth of rows:
    pubnewlength=solArray3.length * aArray[indexA].length;
    //Fill TempArray
    y=solArray3[0].length;
    u=solArray3.length;
    tempArray=new int[u][y];
    // Use system.arraycopy to copy solArray3 into tempArray -- How ?
    // Change the size of arrow to proper size -- How ?
    solArray3 = (int[][]) arrayGrow(solArray3);
    // Join operation - Still under construction
    for(int i = 0, k = 0; i < tempArray.length; i++)
                   for(int j = 0; j < set3.length; j++)
                                     for (q=0;q<=2;q++)             
                                      { solArray3[k][q] = tempArray[i][q];}
                                     solArray3[k][q]= aArray[indexA][j];
                                     ++k;
    } // End jointwoArrays method
    // This module is from http://www.java2s.com/ExampleCode/Language-Basics/Growarray.htm
        static Object arrayGrow(Object a) {
        Class cl = a.getClass();
        if (!cl.isArray())
          return null;
        Class componentType = a.getClass().getComponentType();
        int length = Array.getLength(a);
        int newLength = pubnewlength;
        Object newArray = Array.newInstance(componentType, newLength);
        System.arraycopy(a, 0, newArray, 0, length);
        return newArray;
    } // End ClassI deeply appreciate your help with these 3 questions :
    1. How can I use system.arraycopy to copy my two dimensional array? I have searched but examples seem to be about one dim arrays.
    2. How can I change the "static Object arrayGrow(Object a)" , to grow my two dimensional array ?
    3. If you know any codes or articles or java code regarding cartesian products , please tell me.
    Thank you
    Denis

    1. How can I use system.arraycopy to copy my two
    dimensional array? I have searched but examples seem
    to be about one dim arrays.That's because you can't do it in one call. You need to create a loop which copies each 'row".
    >
    2. How can I change the "static Object
    arrayGrow(Object a)" , to grow my two dimensional
    array ?Why do you make it so complicated (generic). Make it take an int[][] array instead, and see the answer from above.
    >
    3. If you know any codes or articles or java code
    regarding cartesian products , please tell me.There are probably lots of them if you google.
    Kaj

  • How do I find the total number of elements in a multi dim array

    How do I find the total number of elements in a single or multi dim array?
    For example, a 2x3 array has 6 elements, and a 2x3x4 has 24. How do I compute this very easily - is there a single VI that does this?
    David
    Solved!
    Go to Solution.

    Use "array size" (array palette) followed by "multiply array elements" (numeric palette)
    (Works also equally well for 3D arrays and higher)
    For a 1D array, just use "array size".
    Message Edited by altenbach on 02-05-2009 05:57 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    NumberOfElements.png ‏3 KB

  • Create a 2-dim array dynamically

    Hello!
    I have had this problem here before but try one moore time :-)
    This is the thing: We have a text-file from which we read. This textfile can be different from time to time. From this textfile we can catch numbers of columns and numbers of rows that a 2-dim array should have. The problem is how one can create this 2-dim array dynamically? We have a while-loop that the program runs inside already. Must one use the while-loop to solve this problem? Or can one solve this with only a for-loop? Hope you understand how I mean :-) Best regards

    OK, I thought you want to read an array of the same size as the actual data in the file. You cannot read a 4x10 array if the file only contains data for a 3x5 array .
    Is the array size determined by the data in the file or by some other calculation?
    I would still read the entire file, then you can cut out a 2D subset using "array subset". This should not be a problem unless you have millions of array elements.
    LabVIEW Champion . Do more with less code and in less time .

  • In the attached vi, I have a 2-dim series of EMGs which I would like to connect with a 1-dim array. How can I do this?

    In the attached vi, de Y values are given for each time as a matrix. The problem is that the y values coming out have to be a 1-dim array, in order to connect this vi with another vi. How can I do this?
    Attachments:
    3-dim_Filter.vi ‏48 KB

    Hi,
    can you post your curve fitting .vi?
    I think you can do this with the reshape array.vi, and take the 2-D array, find out it's size, and multiply the two dimensions together to get the number of elements you need. That'll give you the array as 1-D, but whether it's in the correct order as you need it is another matter.
    It all depends on what the 2-D array is representing, and how much of it needs to go to the "other" .vi
    Hope that helps
    S.
    // it takes almost no time to rate an answer

  • Build a 2-dim array

    Hello!
    Now we have this problem: We start with a for-loop that runs as many times as there are numbers of signals. Then we want to create a 2-dim array. We know the numbers of columns but not number of rows... so the numbers of coumns can not be created dynamically like the number of rows. We thought of somethning with the "initialize array" but then one need to know both the numbers of rows and columns... any idea? Thank you and best regards.

    Typically it ie easiest to use a shift register and build the array by adding new rows. (see attached, LV 7.0).
    If you had something different in mind, please explain.
    (If you expect the arrays to become very large, building arrays this way may cause slowdowns due to memory allocations.)
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    BuildArray.vi ‏33 KB

  • Sort a 2-dim array?

    Hello!
    Now we have the following problem: We need to sort a 2-dim array depending on the values in the first column. Then we need the corresponding row to move to the right place too... we send a VI so you can see an example of how it might look like. So we need (in this case) the first column to sort so we get 1,2 and 3 and so on, so the last row should be 3,4, 392 and 2047.
    We think this might be easy to solve but we need some tip :-) Thank you and best regards.
    Attachments:
    sortarray.vi ‏17 KB

    I wrote my own 2D string array sort routine. It has come in handy many times. You can enter the column number that you want to sort on, and the entire rows are rearranged in the order of the column sort. If your array is numeric, you can easily change the vi to use numerics instead. One day I hope to make it polymorphic. Here it is:
    - tbob
    Inventor of the WORM Global
    Attachments:
    Sort2DArray(str).vi ‏63 KB

  • Shuffling 2-dim array

    Hello,
    i'm working on a game-project for school, now i need a shuffle of an 2-dim array where i've bound imageIcons to.
    public setRandom () {
    randomArray  = new int[numberRows][numberCollumns]; 
    for (int i=0; i<(numberRows-1); i++)
           for (int j=0; j<(numberCollumns-1); j++)
                  randomArray[i][j] = i;
    }So in the setRandom method i need a shuffle of the randomArray.
    Any ideas ?
    tnx

    i know, i've allready used it, but then i have multiple items and that's not good ...
    import java.util.*;
    public class Shuffle
         public static void main (String[]args)
              int numberRows = 3;
              int numberCollumns = 3;
              Random gen = new Random();  // Random number generator
              int [][] randomArray = new int [numberRows][numberCollumns]; 
              //--- Initialize the array to the ints 0-51
              for (int i=0; i<(numberRows); i++)
                   for (int j=0; j<(numberCollumns); j++)
                       randomArray[i][j] = i*numberCollumns+j;
                       System.out.print(randomArray[i][j]+"   ");
                   System.out.print("\n");
              for (int i=0; i<(numberRows); i++)
                   for (int j=0; j<(numberCollumns); j++)
                           int randomPositionR = gen.nextInt(numberRows);
                           int randomPositionC = gen.nextInt(numberCollumns);
                            int temp = randomArray[i][j];
                           randomArray[i][j] = randomArray[randomPositionR][randomPositionC];
                          randomArray[randomPositionR][randomPositionC] = temp;
                          System.out.print(randomArray[i][j]+"   ");
                   System.out.print("\n");
    }

  • How to sort a 2 dim Array ?

    hello
    I would like to sort a 2-dim array of double ( double[][])
    according to the 1st column
    It is possible to sort a 1st dim array (doubel[]) , but the method sort
    of the class Array doesn't work with double[][]).
    I have two (bad) solutions.
    1) Writing a sorting method but I would prefer using the sort' method of java which uses quicksort
    2) Creating a table of objects that implements Comparable but this would decrease performance
    Do you have a better Idea ?
    Thanks a lot

    I would like to sort a 2-dim array of double (double[][]) according to the 1st column
    Which is the first "column"? double[0][x] or
    double[x][0]?
    If it's the second one things get simple: your
    double[][] is really an array of objects where each
    object is an array of doubles. So all you need to do
    is write a custom Comparator for double[] to use the
    sort method:
    compare(Object obj1, Object obj2) {
    double[] d1 = (double[]) obj1;
    double[] d2 = (double[]) obj2;
    return d1[0] > d2[0];
    }Thanks for your so prompt answer.
    I can manage to put the data so that I sort the array according to x as in double[x][0]?
    But WHERE do I have to write the "compare" method ?
    Thanks

  • How to display an Array of ints in an Array of TextFields

    I'm trying to create an array of textfield's, and then create an array of ints and display one of those ints in each textfield. Can anyone please help me?

    Yea after you create the array of textfields and ints, do a for loop with textfield.length limit.
    for(int i = 0; i < textfield.length; i++){
    look in the JTextField API for how to put int into
    a text. I know, but if this is for a class, you have
    figure it out. (You might have to use the Integer object to convert it to a string
    I hope this helps. If you still can't get it, post some code and I'm sure someone will help you through it.
    gl
    kimoS

  • Two dim array

    hello
    it would be really nice if someone could help me with that.
    i am trying to sort an array and i have read that i can do that with a statement called sort(), but it doesn't seem to work.
    this is what i have tried:
    for(int i = 0; i < arr.length; i++)
           for(int j = 0; j < arr.length; j++)
               sort(arr[i][j]);
    }the error i get is:
    Exercise5W2.java [56:1] No method found matching sort(int)
    sort(arr[i][j]);
    ^
    1 error
    thanks for ur help!

    You can use the java.util.Arrays.sort() with and without
    the java.util.Comparator interface.
    First you sort all individual one-dim int arrays,
    then you sort the whole two-dim array.
    Here is how it goes:
    // 2-dim int array example
    int[][] twoDimIntArray = { { 4, 67, 45 }, { 23, 98, 3}, { 2, 68, 112}, { 333, 5, 21 } };
    // First you sort all individual 1-dim int arrays
    for (int i = 0; i < twoDimIntArray.length; i++)
        Arrays.sort(twoDimIntArray);
    // Then you sort the whole 2-dim array (with an house made Comparator)
    Arrays.sort((Object[])twoDimIntArray, new TwoDimIntArrayComparator());
    // Print out the result
    for (int i = 0; i < twoDimIntArray.length; i++)
    for (int j = 0; j < twoDimIntArray[i].length; j++)
    System.out.print(twoDimIntArray[i][j] + " ");
    System.out.println();
    // Here is the Compararor for 2-dim int array objects
    class TwoDimIntArrayComparator implements Comparator
    public int compare(Object o1, Object o2)
    int[] oneDimIntArray1 = (int[])o1;
    int[] oneDimIntArray2 = (int[])o2;
    // First integer of each array to be different,
    // return the comparison
    for (int i = 0; i < oneDimIntArray1.length; i++)
    if (oneDimIntArray1[i] > oneDimIntArray2[i])
    return 1;
    else if (oneDimIntArray1[i] < oneDimIntArray2[i])
    return -1;
    // All integers of the arrays are equal
    return 0;
    public boolean equals(Object obj)
    return false;

  • How to declare an expandable 2-dim Array

    Hi,
    How do I declare a 2-dim array that is can expandable with additional data?

    Look at this example (Catching the ideas of the other guis:
    e.g. create a Class Object which represents a Row
    class Row {
    ArrayList list = new ArrayList(10); //ten columns
    public Object getObject(int x) {
    list.get(x);
    public void setObject(Object o, int x) {
    list.add(x, o);
    Create an Table Object which is able to add your Rows-Objects
    class Table {
    ArrayList rows = new ArrayList();
    public void addRow(Row row) {
    rows.add(row);
    public Row getRow(int x) {
    return (Row) rows.get(x);
    public int getNrOfRows() {
    return rows.size();
    after this, you can fill your Objects like this
    Row row = new Row();
    row.setObject(0, "James");
    row.setObject(1, "Kirk");
    row.setObject(2, "Captain);
    Table table = new Table():
    table.add(row);
    Hope it helps a little bit

  • Converting ResultSet to Multi Dim Array

    Can anyone tell me an easy way of converting a ResultSet to a Multi-Dimensional array
    Thanks Gary

    convert it to a vector of vectors
    then convert the vector of vectors to a 2 dimensional array (array of arrays).
    you should be able to get the code to convert a vector of
    vectors into a 2 dim array from the web site.

  • How to fill up a 3-dim array?

    Hello!
    See the attached vi. We want to fill upp a 3-dim array. The pages are "number". If "true" is true then we want to insert the row that we build inside the case on page number "number". But the problem is that the new element is placed outside the 3-dim array because the pages are not the same size. How can this problem be solved? Maybe we should use "replace element" ? Does anyone have a tip or idea?
    Thank you and best regards.
    Attachments:
    trouble1.vi ‏51 KB

    Hello Ex-jobb,
    if you want to replace an element of an array, than the index has to be inside that array... Otherwise you have to add an element using build array.
    I changed your example a little bit.
    1) Adding a row with your "Replace Array element", but now using two index values. You may change the second index to your needs.
    2) Making the array constant "bigger" by setting a values at index [6,6,6]. You can NOT replace anything inside an empty array!
    Hope this helps,
    GerdW
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    trouble1.vi ‏51 KB

Maybe you are looking for

  • Unable to uninstall itunes so can update

    I've been trying to udate itunes kept getting error & Now trying to follow dirctions by apple forum to uninstall ad then re-install itunes. Now I can not uninstall the componet "Apple Software Update" & "Apple Mobile Device" when I try to uninstall I

  • Problem in downpayment

    Hi Gurus, i posted down payment to vendors through f-48 and the check was cancelled and now i want to reverse the down payment made to vendors how it has to be done in sap, it's urgent, please help me out sd/- Sreeni.P

  • Help understand Visual Communicator Live Streaming

    Up to know I run live streaming through our Steaming server using FMS and Flash Media Live Encoder as we only needed one camera for live video feeds. We are looking at the ability now to use 2 live cameras and also the ability to snap in pre recorded

  • Search one forum

    Search doesn't seem to be restricting itself to the forum I'm in. I searched it the iCal and AppStore forums for font size When I was in the AppStore forum I fleetingly saw a result for iCal font size. Yet when I search in iCal forum for that thread,

  • Syc music to my new 3gs is being doubled

    hey all i just got a brand new iPhone 3GS 32GB. once I got it home I charged it up, installed itunes from the apple site (the latest I assume). after I installed itunes and plug my new iPhone in it said to update to the latest firmware 3.1.2 so i did