AFAIK you can't because the ActionListener
will be created first and at that time must have access to the final variable login
which isn't initialized yet.
The order of calls would be like this:
- create an instance of the
ActionListener
- pass that instance to the
LoginFrame
constructor - assign the created frame to
login
Now assume the ActionListener
constructor would access login
- it wouldn't be initialized yet and would cause an error.
To fix this you'd need to create the frame first and then set the ActionListener
, i.e.
final LoginFrame login = new LoginFrame();
login.addActionListener( new ActionListener() { ... } );