When we implement Listener, Renderer or Editor, inside methods how Java its calling automatically?
Code:
Class A implements ActionListener{
A(){
//bla bla
//bla bla
this.addActionListener(btn);
}
public void actionPerformed(ActionEvent e){**// How actionPerformed method called //automatically if we register button**
}
}
How its calling actionPerformed method automatically after registering button object? We are just passing the btn object into addActionListener(btn). How inside its calling that method?
I checked through netbeans inside addActionListener method*. There is no calling method of actionPerformed method. Also if we register it keeps on working. Is it calling by thread anywhere inside? But i checked source code. nothing is there. How?
Events are dispatched from an
EventListenerList, owned by the parentJComponent, using a convention outlined in the API and discussed here. Editors and Renderers are evoked by the owning view component.Addendum: Can we create interface same as it is? How?
Yes,
JFreeChartis a fairly accessible example. Although a chart is not itself aJComponent, it uses the same model for its own events.