• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create a JButton with an ActionListener that will allow me to quit JFrames .

 
Mark Toddd
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
salvin francis
Bartender
Posts: 1407
18
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Toddd
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!