Hi, I am trying to determine the type of the object that generates an action event. In my case, my JMenuItem an JButton register with the same event listener. In actionPerformed method, i need to tell which object generates the event. ActionEvent.getSource() method gives me the object. How can i tell which class(JMenuItem,JButton) they belong to? Thanks.
after you get the object you the getClass() method on it and then the getName() method on that class. Object myObject=mouseEvent.getSource(); Class myClass=myObject.getClass(); System.out.println(myClass.getName());