0

Hello Members,

I have a Class_A which extends a JPanel. This JPanel is inside of a JFrame. In Class_A, I have a series of images (stored in an ImageIcon array) and another image, let's call it Image_A, which is also a ImageIcon type. How do I make Image_A a background image for Class_A and also be able to show the series of images on top of this background?

If the above is not possible, can I make two classes (which extend from JPanel) and layer them on top of another and using the setOpaque(false) method?

I would be grateful for any help.

Thank you!

3
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by sciprog1
0

Well, all you need to do is paint on the panel.
So in the class that extends JPanel create the paintmethod

public void paintComponent(Graphics g) {
         super.paintComponent(g);
 Graphics2D g2d = (Graphics2D) g;

then simply draw onto the panel

g2d.drawImage(bgImage,0,0,null);
g2d.drawImage(character,0,0,null);

this will draw the background image first, then draw everything else above it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.