Tekforums

Chat => Entertainment & Technology => Topic started by: M3ta7h3ad on March 28, 2006, 15:44:42 PM

Title: Er...Sam?!
Post by: M3ta7h3ad 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?
Title: Er...Sam?!
Post by: Christopher Monkey 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
Title: Re:Er...Sam?!
Post by: M3ta7h3ad 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?
Title: Er...Sam?!
Post by: GroovyPigThing on March 28, 2006, 18:14:15 PM
cant you just do

for (all elements i of array) {

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

}
Title: Er...Sam?!
Post by: M3ta7h3ad 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
Title: Er...Sam?!
Post by: Christopher Monkey 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
Title: Re:Er...Sam?!
Post by: M3ta7h3ad on March 28, 2006, 20:00:02 PM
Ahh hell not so good.

"non static method append cannot be accessed from a static context."
Title: Re:Er...Sam?!
Post by: M3ta7h3ad 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)
Title: Er...Sam?!
Post by: GroovyPigThing 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");
}
Title: Er...Sam?!
Post by: M3ta7h3ad 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?
Title: Er...Sam?!
Post by: Christopher Monkey on March 28, 2006, 21:05:07 PM
He programs in Java?!?!?!?
Title: Er...Sam?!
Post by: GroovyPigThing on March 28, 2006, 21:35:51 PM
^^ what he said ;)
Title: Re:Er...Sam?!
Post by: M3ta7h3ad 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
Title: Er...Sam?!
Post by: cornet on March 28, 2006, 23:53:25 PM
Java only just got a foreach loop ... LOL
Title: Re:Er...Sam?!
Post by: M3ta7h3ad 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.
Title: Er...Sam?!
Post by: Christopher Monkey on March 29, 2006, 09:39:01 AM
Thats pretty good M3.... id love to look at the code you used for it all!
Title: Re:Er...Sam?!
Post by: M3ta7h3ad on March 29, 2006, 10:29:53 AM
lol righty! just done my demo :)

Not slept a wink, and probably wont today either so much damn work this week.

Added a "fit to window" function in the 5 minutes before my demonstration, and had to get around a gazillion errors including changing all the damn for each loops and stringbuilders I put in, as the Macs here in cardiff uni dont have java 1.5 installed.

Grrr... dont know why they made it so we have to demo on them they are friggin horrible for programming. Will add a fresh screenie montage with the new panel in :) looks quite nice.

Comments from the demo were that im a borderline first, depending on how good the short report I write about the program is. woot!!! :)
Title: Er...Sam?!
Post by: Christopher Monkey on March 29, 2006, 10:32:52 AM
Coolies..... Just wanted to see your code to see how youd done it... havent picked up java since july!!
Title: Re:Er...Sam?!
Post by: M3ta7h3ad on March 29, 2006, 10:41:33 AM
Ill post the code once its all been assessed and marked :) Dont want someone nicking my code and then me getting done for plagiarism cause someones googled it up. Should be alright to post up in a few weeks :)

(its not tidy however... rather messy code, with several bodges :) but it works :))
Title: Er...Sam?!
Post by: Christopher Monkey on March 29, 2006, 10:44:48 AM
Now thats the kind of coding thatll get you a job with micro$oft
Title: Re:Er...Sam?!
Post by: M3ta7h3ad on March 29, 2006, 10:56:00 AM
What sucks is that my program suffers from an actual documented bug on the java bug site. It was found by another one of my mates here when he was coding his.

Basically if you shove a JPanel in a JScrollPane and set the layoutmanager to flowlayout JScrollPane screws up completely and disregards max min sizes and whatnot.

So instead of my thumbnails making a nice page of thumbnails I can scroll down, it just plows straight across and makes the panel huge and scrolls horizontally. However it does work from time to time... it depends on what it feels like.
Title: Er...Sam?!
Post by: Christopher Monkey on March 29, 2006, 11:13:22 AM
lol.... dont you just love bugs!!
Title: Er...Sam?!
Post by: Christopher Monkey on March 29, 2006, 13:29:05 PM
M3.... how are you reading you image files in to your app? Does the app seach your HDD or rdo you have to manually assign them / their folder?
Title: Re:Er...Sam?!
Post by: M3ta7h3ad on March 29, 2006, 18:05:20 PM
my app uses a JFileChooser and loads the files in a chosen directory into a files array.

it then gets the current working directory of the jFileChooser and appends "\\"+files[j] to it to start iterating through the images.
Title: Er...Sam?!
Post by: Christopher Monkey on March 29, 2006, 21:09:15 PM
Fair enough...could you expand it easily to encompass a whole machine along the lines of picassa?
Title: Re:Er...Sam?!
Post by: M3ta7h3ad on March 30, 2006, 00:54:21 AM
erm.. itd be a wee bit more complex in that Id have to identify directories and what not, but yeah dont see why it wouldnt be possible. :)
Title: Er...Sam?!
Post by: Christopher Monkey on March 30, 2006, 10:27:16 AM
Surely you could just set it to trawl from root, and if it found any files ending .jpg, .gif etc it added them into the thumbnail window, with a tag specifying where it had come from?
Title: Er...Sam?!
Post by: M3ta7h3ad on March 30, 2006, 11:25:35 AM
Quote from: Christopher Monkey
Surely you could just set it to trawl from root, and if it found any files ending .jpg, .gif etc it added them into the thumbnail window, with a tag specifying where it had come from?


That would be the issue.

How would it trawl without finding out that a file is a directory.

Also whats root? they could be like me, have a multi harddrive machine. Id need to augment the program for it to detect the different volumes/partitions on a machine... or at least offer an interface for the user to input it, itd be poor design if it was a case of enter in the drive letter... as opposed to a list of volumes and Tick boxes.

It wouldnt take much more work to be honest but meh, also afaik java only handles jpg and gif files as icons and images, so png, tiff, bmp, and the other million and one formats out there wouldnt work in it without some hefty bodgage. :)

And youd probably need to implement a binary tree of stacks to keep track of the files, which is a whore in itself to implement :) Its a lot more than just "trawl root" :) lol.

While my program does pretty things with images and stuff the reason it is simple is because it does no trawling :D lol
Title: Er...Sam?!
Post by: Christopher Monkey on March 30, 2006, 13:03:53 PM
Good point.... like i said earler... ive not touched it for a year, so appologies for over simplifiying the problem :D
Title: Er...Sam?!
Post by: M3ta7h3ad on March 30, 2006, 13:37:40 PM
Quote from: Christopher Monkey
Good point.... like i said earler... ive not touched it for a year, so appologies for over simplifiying the problem :D


lol no worries mate.

Its not too complex, in fact it would make for a good project, and I have libraries ive written myself that I could import in and use for some of the stuff (binary tree stack crap), but it would just take ages. Perhaps a summer project :)