View Single Post
Old 06-11-2012, 06:43 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,657
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Don't. Keep them separate, one to present the output, and one to process the data.
There are several routes you can go with though. You can take a Document type, or a StringBuilder and append to that for example, or you can simply return a string. I'd do neither and opt for using single property accessor's instead, but if I were to group them I'd return a string:
PHP Code:
public String display()
{
    
StringBuilder sb = new StringBuilder();
    
sb.append(name);
    
sb.append(" (");
    
sb.append(address);
    
sb.append(") has $");
    
sb.append(balance);
    return 
sb.toString();
}

// Used
jtText.setText(object.display()); 
Unfortunately I don't believe there is a really generic interface to work with when it comes to the swing JTextArea. Document I think is the lowest you can really go, and its still a javax.swing.text type. There's some patterned approaches you can follow as well, but those are more advanced and require a good understanding of OOP to implement.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
jimutt (06-14-2012)