| Author |
How to create a JButton with an ActionListener that will allow me to quit JFrames .
|
Mark Toddd
Greenhorn
Joined: Jan 05, 2010
Posts: 11
|
|
Hi all.
Hope this makes sense, I've tried to work it out but no luck as yet. So here's my question.
How do I go about calling a class who's function is to exit a JFrame from more than one JFrame?
In my code below I have a JFrame with 2 JButtons. One that opens another instance of a JFrame and a JButton that quits the application. I would be like to be able to place another JButton that also quits on the second JFrame using the class code below thereby avoiding having to write it twice. Is this possible.
again
I'm a complete noob so any hints etc much appreciated.
Thanks guys.
|
"What you talkin' bout Willis?"
|
 |
salvin francis
Ranch Hand
Joined: Jan 12, 2009
Posts: 915
|
|
Your indentations are not proper,
Lets analyze the issue, what does Quit class do when an action is performed:
It executes the function:
This is a call to stop your program and quit everything.
As i can guess, this is not the behavior you require.
There is a function called dispose() in Jframe that you might want to look at,
Also I see no purpose why Thing and Quit should be static classes.
|
My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8566
|
|
Mark,
Welcome to the Ranch.
Having multiple base frames is a bad bad idea. Instead use a single JFrame and JDialog (check out JOptionPane for details on how to create and use modal dialogs)
Check out what JFrame#setVisible(boolean isVisible) does.
Swing related. Moving.
In future please post your UI questions in the Swing forum.
http://faq.javaranch.com/java/CarefullyChooseOneForum
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Mark Toddd
Greenhorn
Joined: Jan 05, 2010
Posts: 11
|
|
Thanks for the tips guys.
I'll be studying Java toward the end of the year at uni and am trying to get to grips with some of the basics.
I'll be sure to post in the right forum next time.
cheers
|
 |
 |
|
|
subject: How to create a JButton with an ActionListener that will allow me to quit JFrames .
|
|
|