I have
ActionListener actionListenerRing = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
defined in my class constructor. How to call actionPerformed method form main method?
I just wanted to know If i can call action listener directly form any other part of my class, OR I should move code form action listener to other method to be accessible to both ActioListener AND other class methods.
Typically, you do not create a listener without attaching it to something. So if your
mainmethod must call such anActionListenerdirectly something might be wrong with your design. Perhaps you can comment on what you try to achieve.You might want to read the whole observer design pattern, but in short you add your listener to another object if you want to be informed when it performs an action. For example:
In the above example, the button will inform the
ActionListenerI added when it’s pressed, and I can react on that by placing the relevant code in theactionPerformedmethod. But I am not going to call my listener myself.