• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextArea

 
Peachy Manasis
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2600
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2600
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
they are all arranged horizontally....


So you need to add a new line string ("\n") every now and then.
 
Peachy Manasis
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2600
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Maneesh Godbole
Saloon Keeper
Posts: 11073
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this thread to a more suitable forum.
 
Peachy Manasis
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2600
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2600
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
*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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic