aspose file tools*
The moose likes Java in General and the fly likes How I can add() random in JFrame? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How I can add() random in JFrame?" Watch "How I can add() random in JFrame?" New topic
Author

How I can add() random in JFrame?

Babis Papadopoulos
Greenhorn

Joined: Dec 11, 2012
Posts: 17
I try to make the memoryCard Game...

Is there a way to add(labels) in a JFrame window RANDOM?

I use FlowLayout and I have:
add(l1);add(l2);add(l3);add(l4);
If I write somthing like this: add(l3);add(l4);add(l1);add(l2); changing series of images.. That's I want... to add the labels with different position every time..

If not, is there a way to put with different row (random) the images in labels?
I have this way to put the images:
imageOfLabel1 = imageOfLabel2 = "im1.jpg";
imageOfLabel3 = imageOfLabel4 = "im2.jpg";


Sorry about my English! : )
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

what you want to do can be done, no problem. you need to think about the problem some more. store the images in a collection of some sort (ArrayList, etc). then have a method which randomly selects one of them.

just add your JLabels once(in the constructor usually). reassign what each displays.


SCJP
Visit my download page
Babis Papadopoulos
Greenhorn

Joined: Dec 11, 2012
Posts: 17
Ok thanks! I 'll try this!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How I can add() random in JFrame?