Detecting collision in a GUI game

I am a beginner in Java GUI and I'm trying to make a game in which you have to save a white object from multiple randomly falling green objects.

But I'm not able to figure out how can I detect whether there is a collision between the objects or not.

This is my Box class :

import java.util.Random;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class Box extends JPanel{
    Random random=new Random();
    int location;
    int XLocation=-20;
    int speed;
    int size;
    int i=0;
    public int Location(){
        return location=random.nextInt(500);
    }
    public int Speed(){
        return speed = random.ints(1, 1, 5).findFirst().getAsInt();
    }
    public int Size(){
        while(true){
            size=random.nextInt(40);
            if(size>10)
            break;
        }
        return size;
    }
    public void paint(Graphics g){
        g.setColor(Color.GREEN);
        g.fillRect(location, XLocation, size, size);
    }
    public Box(){
        Size();
        Location();
        Speed();
    }
    public void update(){
        if(XLocation>=Dodger.Height){
            Location();
            Speed();
            Size();
            XLocation=-20;
        }
        
        if(XLocation<=Dodger.Height){
            XLocation +=speed;
        }
    }
}

and this is my Dodger class :

import java.util.Random;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
public class Dodger extends JPanel{
    
    public static final int Width = 400;
    public static final int Height = 400;
    public static int pos = 180;
    public static double score=0;
    Box[] squareArray = new Box[10];
    public Dodger(){
        for (int i = 0; i < squareArray.length; i++)
            squareArray[i] = new Box();
    }
    
    public void paint(Graphics gr){
        gr.setColor(Color.BLACK);
        gr.fillRect(0, 0, 400, 400);
        gr.setColor(Color.WHITE);
        gr.fillRect(pos, 340, 20, 20);
        gr.setColor(Color.CYAN);
        gr.fillOval(pos+2, 345, 5, 5);
        gr.setColor(Color.CYAN);
        gr.fillOval(pos+13, 345, 5, 5);
        gr.setColor(Color.RED);
        gr.fillRect(pos+6, 355, 8, 1);
        for (Box aSquareArray : squareArray) {
            aSquareArray.paint(gr);
        }
    }
    
    public void update(){
        for (Box aSquareArray : squareArray) aSquareArray.update();
    }
    
    public static void main(String args[])throws InterruptedException{
        Box B=new Box();
        Dodger dodge=new Dodger();
        JFrame frame=new JFrame("Dodger");
        frame.add(dodge);
        frame.setVisible(true);
        frame.setSize(Width, Height);
        frame.addMouseMotionListener(new MouseAdapter (){
            @Override
            public void mouseMoved(MouseEvent e){
                int clicks=e.getX();
                if(clicks>0&&clicks<380){
                    pos=clicks;}
                else{}
            }
        });
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        while(true){
            dodge.update();
            dodge.repaint();
            Thread.sleep(10);
            score=score+0.1;
        }
    }
}

Please help me with the codes

Thanks in advance