Draw two intersecting rectangles and color their intersection black.

Use draw to draw the outline of box1 and box2. Create a third rectangle, box3, where the two rectangles intersect. Use fill to draw box3 as a filled rectangle.

Here is a sample program output:


Complete the following file:


import javax.swing.JComponent; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; public class IntersectionComponent extends JComponent { public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; Rectangle box1 = new Rectangle(5, 10, 100, 120); Rectangle box2 = new Rectangle(50, 60, 100, 120); // your work here ... ... } }

Use the following file:


import javax.swing.*;

   Shows a frame with two rectangles
public class IntersectionViewer
   public static void main(String[] args)
      JFrame frame = new JFrame();
      frame.setSize(300, 400);
      IntersectionComponent component = new IntersectionComponent();