Accessing child elements within a JFrame or JPanel

Accessing child elements within a JFrame or JPanel

I am currently writing a small program. Within the program, I have a JPanel that contains 400 text boxes set out in a 20 x 20 grid.

I am currently writing a small program. Within the program, I have a JPanel that contains 400 text boxes set out in a 20 x 20 grid.

Part of he program works on assigning a color to a variable. When the user then clicks on one of the textboxes, the background color is changed. This is written within Netbeans and all visual items are set out using the Design manger (plus altering the layout manager to suit).

I have no issue with the design, the allocating of a color to a variable or even writing individual code that uses a mouse click event handler to set the background color to the color variable.

The reason for the question is at present, I need to write code for all 400 text boxes to make this work. Is there a way knowing which textbox is clicked and assigning the color, without writing code for all 400 textboxes, maybe via the parent (JPanel)?

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Java Fundamentals: Learn Java for absolute beginners |Simpliv

Java Fundamentals: Learn Java for absolute beginners

Java Essentials : Learn Core Java From Basic to Advance

Learn Java Programming Using Practical Assignments. Start Building Back-end Web Applications Robust Test Automation Frameworks By End Of The Course. Learn More!

Fundamentos de Java: Aprende Java desde cero, sin misterios | Simpliv

Fundamentos de Java: Aprende Java desde cero, sin misterios