I have a class which implements ActionListener
. My actionPerformed()
method runs fine. However, there are some things I want to do once before my program starts to run actionPerformed()
. I could put a boolean
in actionPerformed()
and just run it once that way, but I was looking for something cleaner. I cannot just use my constructor, because I need a fully constructed object for what I am trying to do. Is there a way to add a method such as initialize()
or start()
which will run before actionPerformed()
starts?
Some sample code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Game implements ActionListener {
public Game() {
// Constructor
}
public void initialize() {
// I want a method of some sort here which is run before the main game
// loop so I can set it up
}
@Override
public void actionPerformed(ActionEvent e) {
// main game runs
}
}