aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextArea" Watch "JTextArea" New topic
Author

JTextArea

Peachy Manasis
Greenhorn

Joined: Dec 04, 2010
Posts: 22
hello again... i had another problem....it said... create a magic square 7x7... and use JTextArea as output...
here is my humble code...



as you can see... i only used System.out.print...
first of all... what is a JTextArea??? and how do i insert the magic square into it???
Thank you very much!!!
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2227
    
    8
first of all... what is a JTextArea???


Ahhh, read the API to find out. Not only will you find some useful methods but you will find a link to the Swing tutorial that gives an example of using a text area.
Peachy Manasis
Greenhorn

Joined: Dec 04, 2010
Posts: 22
i tried...
but i only managed this....



and it doesn't print out right.... they are all arranged horizontally.... how can i make them look like a normal magic square?
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2227
    
    8
they are all arranged horizontally....


So you need to add a new line string ("\n") every now and then.
Peachy Manasis
Greenhorn

Joined: Dec 04, 2010
Posts: 22
i don't mean to contradict you or anything... but... far as i know...the magic square is a 2d array so i don't get how to insert new lines for every sixth number...
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2227
    
    8
Look at your nested loop that creates the output String. Somewhere in the loop you need to insert the newline string. I'll let you figure out where you need to do this.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3097
    
  33

To the OP: Were you able to solve this issue? You just need to add an "\n" once you have completed one row of values.


Mohamed Sanaulla | My Blog
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

Moving this thread to a more suitable forum.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Peachy Manasis
Greenhorn

Joined: Dec 04, 2010
Posts: 22
i kind of get it... but i don't know how to add the \n... its after the first for loop where i should put it, right??? but i wonder if a System.out.print would work since its a JTextArea...
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2227
    
    8
I don't know how to add the \n...


Why? What is so confusing?



You know how to add a string containing a single space. What is different about adding "\n"?
Peachy Manasis
Greenhorn

Joined: Dec 04, 2010
Posts: 22
but i already have it on line 29... and if i transfer it under the first loop.. i get a ; expected error...
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2227
    
    8
but i already have it on line 29... and if i transfer it under the first loop


You can't transfer it out of the loop. You need to build the string in two places:

a) first you add each value in the row followed by a space
b) when you finish each row you need to add a new line character.

i get a ; expected error...


Well then add a ;. I can't tell you what to do because I can't see your code. Take some time to think about it and don't be so dependent on people in the forum spoonfeeding the code to you. You don't learn anything if you don't learn how to resolve your compile errors.
Peachy Manasis
Greenhorn

Joined: Dec 04, 2010
Posts: 22
*sigh*
sorry bout that.. but i think its one of the errors indirectly related to my mistake or something... im pretty sure i have the semicolon... just finding out what the "real" problem with my code...
Sorry....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextArea