The getSource () method returns the event source, is there any method that returns the event source type, whether it was a jlabel, or jbutton, something like this?
The getSource () method returns the event source, is there any method that returns the event source type, whether it was a jlabel, or jbutton, something like this?
You can use the instanceof in an if, checking which class belongs to the object, eg
if(getSource() instanceof JButton){
//Foi clicado em um botão
}
else if(getSource() instanceof JLabel){
//Foi clicado em uma JLabel
}
Suppose you have a _var
variable that stores the event source, obtained from getSource ().
You can get the type of this (and any other) variable with getClass (). The comparison can be made like this:
_var.getClass() == JButton.class