I’ve got a class that extends JFrame…
I then assign it to a variable
JFrame frame = this;
I now need to pass this frame into an actionListener class called LoginListener but to do that I need to pass it to a class AppLoginComponents first that extends JPanel and this class has an instance of LoginListener(information,signin, frame)
So it’s like this
Class extending Frame -> AppLoginComponents -> LoginListener
The reason i’m doing this is that the LoginListener needs to quit the application if the user hasn’t logged in within 2 minutes. I am planning to dispose the frame. I don’t think a static variable would be ideal would it?
No, don’t use a static variable. Yes, it’s fine to pass references around. You can also get a reference to the containing top level window via a
SwingUtilitymethod, calledgetWindowAncestor(Component c).But this begs a question — why have a class extend JFrame? Are you overriding any of JFrame’s methods?