Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How I can add() random in JFrame?

 
Babis Papadopoulos
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Babis Papadopoulos
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks! I 'll try this!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic