Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Call windowClosing from JButton

  1. #1
    Member
    Join Date
    Apr 2013
    Posts
    43
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Call windowClosing from JButton

    Hello!

    I have a JFram, a JButton and wonder if it is possible to somehow call the windowClosing-method from a click at the JButton. The reason why I'm using windowClosing instead of windowClosed is when someone click at the JButton, or the default close button in the right corner, the program ask if one really want to exit the program.

    Hank


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Call windowClosing from JButton

    Generally, yes. The JButton has an actionListener which has an actionPerformed() method. In the actionPerformed() method, call the windowClosing() method. If you want more specific help, show some relevant code.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Call windowClosing from JButton

    Why call the windowClosing method? That is normally done by the jvm in response to a user action.
    Is the button supposed to close the window in the same way as a click on the window's system menu close?

    You could make a method that both listeners call to ask the question and return the user's response to the "are you sure" question.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member tonu's Avatar
    Join Date
    Dec 2013
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Call windowClosing from JButton

    i think a program should have one frame and many frame containers, and should use show/hide.

Similar Threads

  1. call by value and call by reference
    By Appu14 in forum The Cafe
    Replies: 1
    Last Post: September 2nd, 2012, 06:58 AM
  2. How to call tablle
    By matsnys in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 16th, 2012, 11:53 AM
  3. How to call table?
    By matsnys in forum Member Introductions
    Replies: 1
    Last Post: August 15th, 2012, 01:49 PM
  4. Call by Reference & Call by Value
    By Lokesh in forum Java Theory & Questions
    Replies: 1
    Last Post: February 21st, 2011, 01:19 PM
  5. Call with a different signature
    By brajesh in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 15th, 2010, 02:05 PM