Drawing a gradient-filled shape in Swing

Main.java:

import java.awt.event.*;
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;
 
      GradientPaint gp = new GradientPaint(20, 50, Color.red, 100, 130, Color.blue, true);
      g2d.setPaint(gp);
      g2d.fillRect(20, 50, 80, 80);
      g2d.setColor(Color.black);
      g2d.drawLine(20, 50, 100, 130);
 
      gp = new GradientPaint(140, 50, Color.red, 220, 130, Color.blue, false);
      g2d.setPaint(gp);
      g2d.fillRect(140, 50, 80, 80);       
      g2d.setColor(Color.black);
      g2d.drawLine(140, 50, 220, 130);
 
      gp = new GradientPaint(260, 60, Color.red, 270, 60, Color.blue, true);
      g2d.setPaint(gp);
      g2d.fillRect(260, 50, 80, 80);
      g2d.setColor(Color.black);
      g2d.drawLine(260, 60, 270, 60);
 
      gp = new GradientPaint(380, 60, Color.red, 390, 60, Color.blue, false);
      g2d.setPaint(gp);
      g2d.fillRect(380, 50, 80, 80);
      g2d.setColor(Color.black);
      g2d.drawLine(380, 60, 390, 60);
   }
 
   public static void main(String []args) {
      Main main = new Main();
      main.setSize(480, 160);
      main.setVisible(true);
   }
}