0

I know how to draw shapes and stuff in Java and know that more recently-drawn shapes stack up on previously drawn shapes, but how do you draw one shape under another? Like let's say you filled a Rectangle() r1, but then filled another Rectangle() r2 and had it display under r1. How would one do that? Other than just redrawing r1 over r2?

c0der
  • 18,467
  • 6
  • 33
  • 65
MineEnim
  • 1
  • 1
  • You need to tell us which library you use, or best post [mcve] showing what you did. If you use [swing](https://docs.oracle.com/javase/tutorial/uiswing/painting/index.html) for example, `paintComponent` does exactly that: paints each shape over previously painted shapes. – c0der Feb 24 '19 at 08:47
  • I'm using Swing. I would have something like `Graphics2D g2; Rectangle r1 = new Rectangle(0, 0, 10, 10); Rectangle r2 = new Rectangle(2, 2, 10, 10); g2.fill(r1); g2.fill(r2);` using `paintComponent` but I was wondering if there were a way to draw `r2` under `r1` without redrawing `r1`. I didn't mention the library because I would switch libraries if I had to to draw one shape under another. – MineEnim Feb 24 '19 at 17:08
  • What did u try ? post your code. – c0der Feb 24 '19 at 17:54

0 Answers0