Author Topic: Er...Sam?!  (Read 5579 times)

Er...Sam?!
on: March 28, 2006, 15:44:42 PM
Just a quick query hopefully.

System.out.println(); - when shoved in a for loop does quite a nice job outputting an array/iterator full of stuff.

Is there anything that I can use to do it in a gui? like a scrollable gui element sort of like a textbox I guess.

How would I do it?

Er...Sam?!
Reply #1 on: March 28, 2006, 15:56:16 PM
off the top of my head, define your text area, then use
Code: [Select]

tJTextArea.append("Text");

where tJTextArea is the name of your text area

Re:Er...Sam?!
Reply #2 on: March 28, 2006, 15:59:10 PM
Would I need to make a string buffer for that and keep adding to it with \n between each line and then output it in one go?

or could just use

jTextArea.print(array[j]);

and it would make a lovely new line all of itself?

Er...Sam?!
Reply #3 on: March 28, 2006, 18:14:15 PM
cant you just do

for (all elements i of array) {

 textarea.append(array + "\n");

}

Er...Sam?!
Reply #4 on: March 28, 2006, 18:50:50 PM
Quote from: GroovyPigThing
cant you just do

for (all elements i of array) {

 textarea.append(array + "\n");

}


:o Dude if that works. I will promise never to crush you to death ever again :D

Er...Sam?!
Reply #5 on: March 28, 2006, 19:35:40 PM
Yea.....

Code: [Select]

while(array[i]!="\0")
{
   tJTextArea.append(array[i] + "\n");
   i++;
}


would do the same thing and would work for a flexible sized array

Re:Er...Sam?!
Reply #6 on: March 28, 2006, 20:00:02 PM
Ahh hell not so good.

"non static method append cannot be accessed from a static context."

Re:Er...Sam?!
Reply #7 on: March 28, 2006, 20:23:26 PM
Got around it :)

Used a StringBuilder object (WOO!!! so much faster than a stringbuffer, thank god for Java 1.5)

Er...Sam?!
Reply #8 on: March 28, 2006, 20:49:19 PM
if youre using java 1.5 you can even use a foreach loop

for (String str : array) {
    textarea.append(str + "\n");
}

Er...Sam?!
Reply #9 on: March 28, 2006, 21:02:00 PM
Quote from: GroovyPigThing
if youre using java 1.5 you can even use a foreach loop

for (String str : array) {
    textarea.append(str + "\n");
}


oooh... now thats a new thing I havent see before.

For each string in an array. May use that elsewhere in my program :)

How did you know this by the way?

Er...Sam?!
Reply #10 on: March 28, 2006, 21:05:07 PM
He programs in Java?!?!?!?

Er...Sam?!
Reply #11 on: March 28, 2006, 21:35:51 PM
^^ what he said ;)

Re:Er...Sam?!
Reply #12 on: March 28, 2006, 22:32:30 PM
Yeah, but ive been programming in Java for the last 3 years. :D lol.

Used to 1.4.2 but not really bothered finding out the latest functions in 1.5

  • Offline cornet

  • Posts: 143
  • Full Member
Er...Sam?!
Reply #13 on: March 28, 2006, 23:53:25 PM
Java only just got a foreach loop ... LOL

Re:Er...Sam?!
Reply #14 on: March 29, 2006, 01:47:28 AM
lol I have to say its quite a nifty function and cornet :P lol some of us have no choice over what languages we want to program :) Personally im learning Ruby on the side :)

http://www.tekforums.co.uk/posts/list/105/8.page#4355

WOOT.. All done.

0 Members and 1 Guest are viewing this topic.