Re: Math.random()
- From: "Jeff Higgins" <oohiggins@xxxxxxxxx>
- Date: Fri, 7 Mar 2008 11:06:03 -0500
maya wrote:
maya wrote:
Jeff Higgins wrote:
Daniel Pitts wrote:
maya wrote:A clear winner. :-))
(I want to have option of displaying photos in a random order insteadTry putting the photos into a List object, and then calling
of in order of img-names (1.jpg, 2.jpg, 3.jpg, etc..))
Collections.shuffle() with that list object as the parameter.
ok, am trying to do this now.. acc to docs it's like a vector except
"synchronized" (not sure what this means..) only thing in Vector you add
elements thus:
vPhotos.addElement(imgsList[i]);
but am having problems here:
ArrayList photos = new ArrayList(); File directory = new
File(System.getProperty("user.dir"));
String[] textFileNames = directory.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jpg") || name.endsWith( ".JPG");
}
});
for (int i=0; i < textFileNames.length+1; i++) {
photos.add(i); // error here...
photos.add(new File(i));
}ok, I think got Collections.shuffle() part..
how do I convert this "i" to an object (since this method takes only obj
as argument..)
and then how do I apply Collections.shuffle() to it??
photos.Collections.shuffle() ?? I dont think so....;)
I really need this today, for some photos I'm putting together for a
friend overseas, sending with a friend who travels today....
thank you very much..
Collections.shuffle(photos, new Random());
only problem now is how to add all nos. to ArrayList (this has to be 1.4
construction, not 1.5..)
and then how to go from Collections.shuffle to this:
for (int i = 0; i < textFileNames.length; ++i) {
File oldFile = new File(textFileNames[i]);
posDot = textFileNames[i].indexOf(".");
_temp = textFileNames[i].substring(0,posDot);
File newFile = new File(i+1 + ".jpg");
oldFile.renameTo(newFile);
}
so imgs are named with nos. at random (i.e., so imgs, after renamed, are
in diff order from orig ones..)
thank you....
.
- Follow-Ups:
- Re: Math.random()
- From: Jeff Higgins
- Re: Math.random()
- References:
- Re: Math.random()
- From: maya
- Re: Math.random()
- From: maya
- Re: Math.random()
- Prev by Date: Re: Math.random()
- Next by Date: Re: Math.random()
- Previous by thread: Re: Math.random()
- Next by thread: Re: Math.random()
- Index(es):
Relevant Pages
|
|