Combining two shapes in Swing

Cast the shapes to areas where you have the methods add, subtract, intersect and exclusiveOr.

Main.java:

import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.*;
 
public class Main extends JFrame {
   public Main() {
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent we) {
            System.exit(1);
         }
      }); 
   }
 
   public void paint(Graphics g) {
      Graphics2D g2d = (Graphics2D) g;
 
      Shape shape1 = new Rectangle2D.Double(80, 50, 40, 40);
      Shape shape2 = new Rectangle2D.Double(20, 60, 160, 20);
 
      g2d.setColor(Color.black); 
      g2d.drawString("normal:", 20, 40);
      g2d.draw(shape1); 
      g2d.draw(shape2); 
 
      g2d.translate(0, 70);
      g2d.setColor(Color.yellow); 
      g2d.fill(combine("add", shape1, shape2));
      g2d.setColor(Color.black); 
      g2d.drawString("area add:", 20, 40);
      g2d.draw(shape1); 
      g2d.draw(shape2); 
 
      g2d.translate(0, 70);
      g2d.setColor(Color.yellow); 
      g2d.fill(combine("subtract", shape1, shape2));
      g2d.setColor(Color.black); 
      g2d.drawString("area subtract:", 20, 40);
      g2d.draw(shape1); 
      g2d.draw(shape2); 
 
      g2d.translate(0, 70);
      g2d.setColor(Color.yellow); 
      g2d.fill(combine("intersect", shape1, shape2));
      g2d.setColor(Color.black); 
      g2d.drawString("area intersect:", 20, 40);
      g2d.draw(shape1); 
      g2d.draw(shape2); 
 
      g2d.translate(0, 70);
      g2d.setColor(Color.yellow); 
      g2d.fill(combine("exclusiveOr", shape1, shape2));
      g2d.setColor(Color.black); 
      g2d.drawString("area exclusiveOr:", 20, 40);
      g2d.draw(shape1); 
      g2d.draw(shape2); 
   }
 
   public Shape combine(String op, Shape shape1, Shape shape2) {
      Area area1 = new Area(shape1);
      Area area2 = new Area(shape2);
      
      if (op.equals("add")) area1.add(area2);
      else if (op.equals("subtract")) area1.subtract(area2);
      else if (op.equals("intersect")) area1.intersect(area2);
      else if (op.equals("exclusiveOr")) area1.exclusiveOr(area2);
 
      return area1;
   }
  
   public static void main(String []args) {
      Main main = new Main();
      main.setSize(200, 400);
      main.setVisible(true);
   }
}