Determine which button is called the actionPerformed method

I am making a labyrinth program in Java, which consists of a MazeButtons grid that extend JButton and have a state field (this is the location of the button and other information about how the labyrinth should work). Another class, MazeFrame, extends JFrame and implements ActionListener. When I create a GUI in the installation class, I add an ActionListener MazeFrame to each button. I want the actionPerformed method in a MazeFrame to check if the action taken by the user is allowed, but for this I need to know which button was clicked.

How do you know which button is called this actionPerformed method?

+2
source share
1

getSource , ,

+3

Source: https://habr.com/ru/post/1608354/


All Articles