hello, i added some images to jpanel, with some animation.
i put some images in a folder, and i m display/moving them on jpanel simultaneously.
my question is can i add images dynamically??
i mean what i want is, i want to add a button on that panel, and when i click on that button, one more image (randomly) should added to my jpanel from that folder.
how can i do this??
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
the code to add the image is identical to
how you'd add it when the frame first opens.
because the frame is now visible, after
adding it you need to have these lines
panel.add(image);//however you add it
panel.revalidate();
panel.repaint();
Punit Jain
Ranch Hand
Joined: Aug 20, 2011
Posts: 902
posted
0
but how even i add add those images on button click one by one, i mean how i get images randomly from my image folder??
above is what i am doing right now.
Randall Twede
Ranch Hand
Joined: Oct 21, 2000
Posts: 4095
1
posted
0
you need to use Math.random()
check the API and tutorials
luck, db
There are no new questions, but there may be new answers.
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
> i mean how i get images randomly from my image folder??
another option, at program startup, is to load them all into a List,
then Collections.shuffle(list) and add them to your panel in the
'shuffled' order of the list.