I am trying to draw several things inside a JPanel
. I am drawing shapes (works), and I also want to fill the JPanel with a picture.
But paintComponent()
only takes one argument. And this gets complicated when I have some extra code for drawing the shapes.
My paintComponent() method is currently like this:
public void paintComponent(Graphics g) {
g2 = (Graphics2D) g;
for (int i = 0; i < shapes.size(); i++) {
Shape s = (Shape) shapes.get(i);
if (s != null)
g2.draw(s);
}
}
I have searched around a lot and cannot find a way to do this.
Does anyone know how to do this, or maybe some workaround?