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:

IntersectionComponent.java

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:

IntersectionViewer.java

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);
      frame.setTitle("IntersectionViewer");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      IntersectionComponent component = new IntersectionComponent();
      frame.add(component);
      frame.setVisible(true);
   }
}