So I am making a class that performs an action when a specific event happens. Basically, a variable gets changed to a different value. What I need to do is store a reference to this object from inside the constructor. Here is the code that I am working with to give everyone a better picture:
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Created by iJason on 8/26/2016.
*/
class ClickListener implements ActionListener {
JLabel label;
public void actionPerformed(ActionEvent event) {
label.setText("I was clicked.");
}
public ClickListener(JLabel label) {
this.label = label;
}
}
So whenever the "actionPerformed" method is called, I want the "label" that is getting passed in to the constructor to actually change. So I need to set a reference to it from the constructor but I am not sure how to do that in Java. Thanks in advance for all the help!