I'm trying to make a Swing program, I currently have an image stretched across the whole screen that acts as a background, and now I just want an smaller image to be drawn on top of this image
My video constructor and draws the background and foreground images:
public Video(BufferedImage foreground, BufferedImage background){
pane = this.getContentPane(); //get the content pane to place components
pane.setLayout(null); //use absolute positioning (using Insets)
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
this.setVisible(true);
this.setBounds(0,0,(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(),(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight());
DrawImage panel = new DrawImage(background);
add(panel);
this.image = foreground;
DrawForeground fg = new DrawForeground(image);
add(fg);
fg.setVisible(true);//don't make image visible until showImageAt() gives it a place to be
}
My drawImage method ( draw foreground is very similar but with a different size)
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
class DrawImage extends JPanel {
private BufferedImage img;
public DrawImage(BufferedImage img) {
this.img = img;
Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
setLayout(null);
}
public void paintComponent(Graphics g) {
g.drawImage(img, 0, 0,this.getWidth(),this.getHeight(), null);
}
}