ニュース
A much better solution is to add the MouseListener to the Panel or Canvas to which you are drawing all these squares. Then, in that MouseListener, do calculation to determine which square was clicked.
現在アクセス不可の可能性がある結果が表示されています。
アクセス不可の結果を非表示にする