Boa tarde pessoal, alguém sabe me informar como posso abrir duas imagens em um mesmo frame utilizando Swing?
Estou tentando carregar as imagens porém ele sobrescreve uma na outra e no final acaba aparecendo só uma.
package br.com.hotel.alura.api.views;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
public class MainPanel extends JFrame {
private Image backgroundImage;
private Image hotelIcon;
public MainPanel() {
super("Menu");
panel();
loadBackgroundImage();
backgroundImageComponent();
addBackgroundImageComponent();
loadHotelIcon();
hotelIconComponent();
addHotelIconComponent();
dimensionPanel();
}
private Image loadBackgroundImage() {
try {
backgroundImage = ImageIO.read(new File("src/assets/img/menu-img.png"));
} catch (IOException e) {
e.printStackTrace();
}
return backgroundImage;
}
private Image loadHotelIcon() {
try {
hotelIcon = ImageIO.read(new File("src/assets/img/aH-150px.png"));
} catch (IOException e) {
e.printStackTrace();
}
return hotelIcon;
}
private Component backgroundImageComponent() {
JPanel painelImagem = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(loadBackgroundImage(), 1000, 0, null);
}
};
return (Component) painelImagem;
}
private Component hotelIconComponent() {
JPanel painelImagem = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(loadHotelIcon(), 0, 0, null);
}
};
return (Component) painelImagem;
}
private void addBackgroundImageComponent() {
add(backgroundImageComponent());
}
private void addHotelIconComponent() {
add(hotelIconComponent());
}
private void dimensionPanel() {
Dimension sizeFrame = new Dimension(1300, 700);
setPreferredSize(sizeFrame);
pack();
}
private void panel() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setVisible(true);
}
}