Go Back   nV News Forums > Software Forums > Software Development

Newegg Daily Deals

Reply
 
Thread Tools
Old 01-26-07, 08:28 PM   #25
Marvel_us
FOOL!
 
Marvel_us's Avatar
 
Join Date: Dec 2005
Location: Miami, Florida
Posts: 3,754
Default Re: Sigh, Java HW Help

So I'd need to create two strings, one that holds the toString for a specific object and assign the other string variable to the first string? Wouldn't the string get replaced after every loop or would it hold all of them?

Then use the joptionpane outside of the loop, right?

Something like:
Quote:
public void DisplayList()
{
for(int i = 0; i < accounts.size(); i++)
{
Customer c = accounts.get( i ) ;

String s = c.toStringCustomer() ;

String r += s ;
}

JTextArea text = new JTextArea(r, 40, 40);
JScrollPane pane = new JScrollPane(text);


JOptionPane.showMessageDialog(null, pane, "Account Information",
JOptionPane.INFORMATION_MESSAGE);

}
__________________
Main Rig
Intel Q6600 QUAD|| Gigabyte P35-DS3L ||XFX 7900GTX|| G.Skill 6GB PC2-6400 || OCZ Agility 60GB SSD || WD 320GB + WD Green 1TB HDD || Samsung 20" LCD || CoolMax 650W PSU ||

60gb PS3 Owner
PSNid: Marvel_us
Marvel_us is offline   Reply With Quote
Old 01-26-07, 09:28 PM   #26
rhink
Registered User
 
Join Date: Jul 2005
Posts: 434
Default Re: Sigh, Java HW Help

Declare the string in a place it won't get overwritten every loop iteration.
rhink is offline   Reply With Quote
Old 01-26-07, 09:35 PM   #27
Marvel_us
FOOL!
 
Marvel_us's Avatar
 
Join Date: Dec 2005
Location: Miami, Florida
Posts: 3,754
Default Re: Sigh, Java HW Help

Got ya, I would only need it to be local to that method right? I don't see a need to have it declared as an instance variable for that class. So this is what I have:

Quote:
public void DisplayList()
{
String r ;

for(int i = 0; i < accounts.size(); i++)
{
Customer c = accounts.get( i ) ;

String s = c.toStringCustomer() ;

r += s ;
}

JTextArea text = new JTextArea(r, 40, 40);
JScrollPane pane = new JScrollPane(text);


JOptionPane.showMessageDialog(null, pane, "Account Information",
JOptionPane.INFORMATION_MESSAGE);
}
}
__________________
Main Rig
Intel Q6600 QUAD|| Gigabyte P35-DS3L ||XFX 7900GTX|| G.Skill 6GB PC2-6400 || OCZ Agility 60GB SSD || WD 320GB + WD Green 1TB HDD || Samsung 20" LCD || CoolMax 650W PSU ||

60gb PS3 Owner
PSNid: Marvel_us
Marvel_us is offline   Reply With Quote
Old 01-26-07, 09:39 PM   #28
Marvel_us
FOOL!
 
Marvel_us's Avatar
 
Join Date: Dec 2005
Location: Miami, Florida
Posts: 3,754
Default Re: Sigh, Java HW Help

Actually now that I try it, it won't work locally it should be an instance variable.
__________________
Main Rig
Intel Q6600 QUAD|| Gigabyte P35-DS3L ||XFX 7900GTX|| G.Skill 6GB PC2-6400 || OCZ Agility 60GB SSD || WD 320GB + WD Green 1TB HDD || Samsung 20" LCD || CoolMax 650W PSU ||

60gb PS3 Owner
PSNid: Marvel_us
Marvel_us is offline   Reply With Quote
Old 01-26-07, 10:40 PM   #29
Marvel_us
FOOL!
 
Marvel_us's Avatar
 
Join Date: Dec 2005
Location: Miami, Florida
Posts: 3,754
Default Re: Sigh, Java HW Help

Gah, it still isn't working. It's displaying information multiple times, there is something wrong with the r += s ; line but I still haven't figured out how to get around that.
__________________
Main Rig
Intel Q6600 QUAD|| Gigabyte P35-DS3L ||XFX 7900GTX|| G.Skill 6GB PC2-6400 || OCZ Agility 60GB SSD || WD 320GB + WD Green 1TB HDD || Samsung 20" LCD || CoolMax 650W PSU ||

60gb PS3 Owner
PSNid: Marvel_us
Marvel_us is offline   Reply With Quote
Old 01-26-07, 11:34 PM   #30
rhink
Registered User
 
Join Date: Jul 2005
Posts: 434
Default Re: Sigh, Java HW Help

Might need a separator between the lines....or actually make them multiple lines.
rhink is offline   Reply With Quote
Old 01-26-07, 11:36 PM   #31
Marvel_us
FOOL!
 
Marvel_us's Avatar
 
Join Date: Dec 2005
Location: Miami, Florida
Posts: 3,754
Default Re: Sigh, Java HW Help

Quote:
Originally Posted by rhink
Might need a separator between the lines....or actually make them multiple lines.
Not sure I'm getting you on that one. What do you mean by make them multiple lines?
__________________
Main Rig
Intel Q6600 QUAD|| Gigabyte P35-DS3L ||XFX 7900GTX|| G.Skill 6GB PC2-6400 || OCZ Agility 60GB SSD || WD 320GB + WD Green 1TB HDD || Samsung 20" LCD || CoolMax 650W PSU ||

60gb PS3 Owner
PSNid: Marvel_us
Marvel_us is offline   Reply With Quote
Old 01-26-07, 11:38 PM   #32
Cinema4DXL
Registered User
 
Join Date: Sep 2004
Posts: 97
Default Re: Sigh, Java HW Help

can you post your output?
__________________
Athlon XP-M 2600+@(200x11.5) | Abit AN7 | 2x512 Corsair XMS PC-3200 | BFG 6800 GT OC (400/1100) w/ NV Silencer 5 | Promise Ultra133TX2 | WD Caviar SE 80GB 8 MB | Seagate Barracuda 7200.7 160GB | Maxtor DiamondMax 10 300GB | Sony 16x DVD-ROM | NEC 3520A | Antec SmartPower 2.0 500w | Koolance PC-601 | Samsung SyncMaster 997DF
Cinema4DXL is offline   Reply With Quote

Old 01-26-07, 11:48 PM   #33
Marvel_us
FOOL!
 
Marvel_us's Avatar
 
Join Date: Dec 2005
Location: Miami, Florida
Posts: 3,754
Default Re: Sigh, Java HW Help

Quote:
Originally Posted by Cinema4DXL
can you post your output?
Sure, this is how it looks when after entering only two customers. What's up with the null on the first one as well?

Quote:
nullAccount Number: 1000 John Smith

Address:
Street: 7669 NW
City: Miami
State:
FL
Zip Code: 33054

Account Balance: 15065.0

Account Number: 1000 John Smith

Address:
Street: 7669 NW
City: Miami
State:
FL
Zip Code: 33054

Account Balance: 15065.0

Account Number: 1001 Rico Suave

Address:
Street: 7899 SW
City: Newark
State:
NJ
Zip Code: 6549

Account Balance: 7800.0
Don't mind the overall layout. I plan making it layout better. Just trying to get it to display the objects correctly first.
__________________
Main Rig
Intel Q6600 QUAD|| Gigabyte P35-DS3L ||XFX 7900GTX|| G.Skill 6GB PC2-6400 || OCZ Agility 60GB SSD || WD 320GB + WD Green 1TB HDD || Samsung 20" LCD || CoolMax 650W PSU ||

60gb PS3 Owner
PSNid: Marvel_us
Marvel_us is offline   Reply With Quote
Old 01-26-07, 11:51 PM   #34
rhink
Registered User
 
Join Date: Jul 2005
Posts: 434
Default Re: Sigh, Java HW Help

Quote:
Originally Posted by Marvel_us
Not sure I'm getting you on that one. What do you mean by make them multiple lines?
Ahh was making an assumption about what your problem was, looks like I was wrong.

About the null- you never initialized your "r" variable. Think about what r += s; is really doing, especially the first time through.
rhink is offline   Reply With Quote
Old 01-27-07, 12:01 AM   #35
Marvel_us
FOOL!
 
Marvel_us's Avatar
 
Join Date: Dec 2005
Location: Miami, Florida
Posts: 3,754
Default Re: Sigh, Java HW Help

Quote:
Originally Posted by rhink
Ahh was making an assumption about what your problem was, looks like I was wrong.

About the null- you never initialized your "r" variable. Think about what r += s; is really doing, especially the first time through.
Yea, I just figured realized that. I initialized it as an empty string now but the duplication problem is still there. I know the problem is the r +=s but I'm going in circles trying to figure out the solution.
__________________
Main Rig
Intel Q6600 QUAD|| Gigabyte P35-DS3L ||XFX 7900GTX|| G.Skill 6GB PC2-6400 || OCZ Agility 60GB SSD || WD 320GB + WD Green 1TB HDD || Samsung 20" LCD || CoolMax 650W PSU ||

60gb PS3 Owner
PSNid: Marvel_us
Marvel_us is offline   Reply With Quote
Old 01-27-07, 07:52 PM   #36
Marvel_us
FOOL!
 
Marvel_us's Avatar
 
Join Date: Dec 2005
Location: Miami, Florida
Posts: 3,754
Default Re: Sigh, Java HW Help

Program complete! Thanks to all for the responses.

Especially Cinema4DXL.
__________________
Main Rig
Intel Q6600 QUAD|| Gigabyte P35-DS3L ||XFX 7900GTX|| G.Skill 6GB PC2-6400 || OCZ Agility 60GB SSD || WD 320GB + WD Green 1TB HDD || Samsung 20" LCD || CoolMax 650W PSU ||

60gb PS3 Owner
PSNid: Marvel_us
Marvel_us is offline   Reply With Quote
Reply


Thread Tools

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Diablo 3 hotfix removes monster damage boost in co-op, Inferno teams breathe sigh of News Archived News Items 0 06-11-12 01:20 PM
Google (partially) loses suit to Oracle over use of Java API's ViN86 Mobile Devices And Smartphones 3 05-17-12 10:25 AM
Judge Declines To Rule That Google Pillaged Java News Archived News Items 0 05-10-12 07:00 AM
BAH! I'm being driven insane by Java Virtual Machine Kruno General Software 9 09-01-02 09:59 PM

All times are GMT -5. The time now is 05:28 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.