title: How can I make a set of clickable circles in Java with Canvas?
body: <p>so I made a grid of 25 circles using Canvas paint, and I want them to be clickable. The clicks should be able to carry out a function. How can I do so?</p>
  
  <p>My code: </p>
  
  <pre><code>import javax.swing.JFrame; //JFrame Class
  import java.awt.Canvas;
  import java.awt.Color;
  import java.awt.Graphics;
  
     public class Driver extends Canvas
     {
        public void paint( Graphics g) {
           g.setColor(Color.RED);
           int rows = 5;
          for (int y=0;y&lt; rows;y++)
              {
              for (int x=0;x&lt;rows;x++)
                 {
                 g.drawOval((x + 1) * 150, (y + 1) *150, 100, 100);
                 }
  
               }
  
        }
        public static void main(String[] args)
        {
           JFrame f = new JFrame("Flow"); //new JFrame
           Driver t = new Driver();
           f.setSize(900,900);//sets size of frame
  
           f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//sets default close operation
  
           f.setVisible(true);//makes panel visible
           f.add(t);
  
          }
  }
  </code></pre>