ImageIcons

P

patrick

I have a PC java application with 100+ images shown via ImageIcons in JLabel
s.

What would be the correct way to do this?
pre read all the image files and create all the 100+ ImageIcons objects at
the start and use as required
OR
just read the image files when needed and create the ImageIcons when
needed.
Im inclined towards the first option.


TIA
patrick.
 
K

Knute Johnson

patrick said:
I have a PC java application with 100+ images shown via ImageIcons in JLabel
s.

What would be the correct way to do this?
pre read all the image files and create all the 100+ ImageIcons objects at
the start and use as required
OR
just read the image files when needed and create the ImageIcons when
needed.
Im inclined towards the first option.


TIA
patrick.

Are you just displaying them or are you actually doing something with
all those JLabels? What are you really doing?
 
P

patrick

Ive a class ImagePanel which is a JPanel in which I show a JLabel. I use
this class to display an image and to animate the image. i.e I create
ImagePanel objects and locate the object (or move it) within the java
application.
patrick
 
K

Knute Johnson

patrick said:
Ive a class ImagePanel which is a JPanel in which I show a JLabel. I use
this class to display an image and to animate the image. i.e I create
ImagePanel objects and locate the object (or move it) within the java
application.
patrick

patrick:

It would probably be a lot more efficient, and easier to code, if you
just drew your images directly onto the JPanel rather than moving
components around.

If for example you wanted to show some animated character, and you had
several images of this character. Load them into your program as either
and Image or BufferedImage. In your run() index a variable for the
number of images and call repaint(). In your paintComponent() draw the
appropriate image. You can even move the images across the screen in
this process.

If you need some code examples let me know.
 
P

patrick

OK thanks for that.
Ill probably stick with it as it is unless it seems slow.
wont know until ive got properly running.

patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top