This week's giveaway is in the Java/Jakarta EE forum. We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line! See I have a feeling you can just invoke the actionListener by creating the object of that class, pretty simple.
I just am curious about how to close the current JFrame? I know how to use setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);, but that doesn't seem to work if I put that in for an actionListener for the apply button.
Ben Jass wrote: I know that Frames don't support actionListeners. I'm just saying that components that are within the JFrame hold actionListeners. Thank you for the second problem help.
Okay. So keep a list of the components which do have ActionListeners, and iterate through that list calling the ActionListener of each component. Although I can't conceive of a design in which closing a frame has the side effect of essentially pressing every button which happens to be in the frame. Is that really what you meant? I would approach the general requirement ("Do something when a JFrame is closed") in a more normal way, namely by providing the JFrame subclass with a "close" method which does the required things, and by having whatever closes the JFrame also call that method.
Or in your particular case, the method would be called "apply" or something sensible like that.
posted 7 years ago
I understand where you are coming from, and you were answering the question in the way I asked it. I'm rather new to the whole GUI thing, the only way I can activate something when let's say I put some text in the JTextField is by pressing "enter" on my keyboard. I want it to be somewhat professional by pressing the apply button which triggers these actions, maybe there is a better way? Also I'm having some trouble with saving the information on the set up screen if I were to re-open it. The set up screen is where this is all taking place.
First setup screen:
Second time I bring up the setup screen after closing it once: