Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-27-2011, 08:49 AM   PM User | #1
Alaskan93
New to the CF scene

 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Alaskan93 is an unknown quantity at this point
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 09:00 AM..
Alaskan93 is offline   Reply With Quote
Old 04-27-2011, 09:07 AM   PM User | #2
gkarthik21
New to the CF scene

 
Join Date: Apr 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
gkarthik21 is an unknown quantity at this point
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
gkarthik21 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:29 PM.


Advertisement
Log in to turn off these ads.