• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

JButton Quick Help  RSS feed

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Last question for the day, how do I make it so that when I click a button like "apply", it automatically closes the current JFrame that is up, and activates all of the actionListener's within the JFrame.
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.

I appreciate the help.
 
Rancher
Posts: 2940
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

and activates all of the actionListener's within the JFrame



Frames don't support ActionListener, so that doesn't make sense.

do I make it so that when I click a button like "apply", it automatically closes the current JFrame that is up



 
Ben Jass
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 23687
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ben Jass
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!