Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Adding rows of Jtextfields.

    Hello, I'm having trouble adding a 8x2 array of jtextfields with "10" in each and have them in a 2d array[][] one for each column and I turn the string to a int and add the next jtextfield, I got one column to add the ints and if more then 8 it will go to the next column in a counter direction. I'm getting mixed up trying to go backwords and add the fields starting from myFields[1][7]. So myFields[0][0] through [0][7] then goes to [1][0] to [1][7] in counter clockwise direction, can't get from [1][7] back to [0][0].

    [CODE]public void actionPerformed(ActionEvent e){

    String currentField = myFields[0][0].getText();
    int string1,string2, total;
    string1 = Integer.parseInt(currentField);

    if(string1 > 1)

    for(int i = 1; i < string1; i++){

    if(i < 8){
    String nextField = myFields[0][i].getText();
    string2 = Integer.parseInt(nextField);
    total = string2 + 1;
    String totalString = String.valueOf(total);
    myFields[0][i].setText(totalString);
    myFields[0][0].setText("1");
    System.out.println("i<8");


    }


    else if(string1 == 1){

    String nextField = myFields[0][1].getText();
    string2 = Integer.parseInt(nextField);
    total = string2 + 1;
    String totalString = String.valueOf(total);
    myFields[0][0].setText("0");
    myFields[0][1].setText(totalString);
    System.out.println("Last if");

    }
    }/CODE]
    Last edited by Alaskan93; 04-27-2011 at 10:00 AM.

  • #2
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Alaskan93 View Post
    Hello, I'm having trouble adding a 8x2 array of jtextfields with "10" in each and have them in a 2d array[][] one for each column and I turn the string to a int and add the next jtextfield, I got one column to add the ints and if more then 8 it will go to the next column in a counter direction. I'm getting mixed up trying to go backwords and add the fields starting from myFields[1][7]. So myFields[0][0] through [0][7] then goes to [1][0] to [1][7] in counter clockwise direction, can't get from [1][7] back to [0][0].

    [CODE]public void actionPerformed(ActionEvent e){

    String currentField = myFields[0][0].getText();
    int string1,string2, total;
    string1 = Integer.parseInt(currentField);

    if(string1 > 1)

    for(int i = 1; i < string1; i++){

    if(i < 8){
    String nextField = myFields[0][i].getText();
    string2 = Integer.parseInt(nextField);
    total = string2 + 1;
    String totalString = String.valueOf(total);
    myFields[0][i].setText(totalString);
    myFields[0][0].setText("1");
    System.out.println("i<8");


    }


    else if(string1 == 1){

    String nextField = myFields[0][1].getText();
    string2 = Integer.parseInt(nextField);
    total = string2 + 1;
    String totalString = String.valueOf(total);
    myFields[0][0].setText("0");
    myFields[0][1].setText(totalString);
    System.out.println("Last if");

    }
    }/CODE]
    assign value zero to the variable string1,string2,total..sumtimes it will take garbage value


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •