Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7667435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:06:06+00:00 2026-05-31T15:06:06+00:00

I have to save the state of the program in a xml when the

  • 0

I have to save the state of the program in a xml when the user clicks the Close Button or another JButton which says Exit on it. I have it so it runs using a WindowListener when the Window is closing it runs it. But that only works if you click the Red X close button, but not when you have the other button. I could run it before I do System.exit(0) in actionListener for button but some of the classes I need information from I do not have access from that place.

This is for the frame.

frame.addWindowListener(new WindowListener(){
    public void windowActivated(WindowEvent arg0){}
    public void windowClosed(WindowEvent arg0){}
    public void windowClosing(WindowEvent arg0)
    {
        myScreen.write.writeToXmlFile(myScreen.pics, myScreen.row, myScreen.col);
    }
    public void windowDeactivated(WindowEvent arg0){}
    public void windowDeiconified(WindowEvent arg0){}
    public void windowIconified(WindowEvent arg0){}
    public void windowOpened(WindowEvent arg0){}
});

This is the code in button.

public void actionPerformed(ActionEvent arg0) {
        System.exit(0);
}

I do not have access to myScreen from the class that has button in it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:06:08+00:00Added an answer on May 31, 2026 at 3:06 pm
    I do not have access to myScreen from the class that has button in it.
    

    JButton#doClick(); can do that

    but correct way could be too (maybe)

    • public void windowClosing(WindowEvent arg0)

    1st. void or class

    • create screenshot

    2.nd void or class

    • setVisible(false) for Top-Level Container(s)

    3rd void or class

    • save applications states

    4th void or class

    • System.exit()

    sure you can put all 4 voids (classes) to the one, but in a.m. case is code only more clear and readable

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Seekbar and I want to save the state to database when
I have a WP7 XNA game that needs to save the state whenever the
I have a save button in a JFrame ;on clicking save the 'save' text
We have repositories which have a Save method. They also throw a Created event
I have a program which automatically launches a phone call when program is started.
I have a save as image feature for charts in my application. The chart
suddenly we have to save kanji (Japanese) in a couple of columns of two
I'm writing a bat script and I have to save the date from a
I am working on an app and i have to save some data in
I have a to save a pdf report into an Oracle DB. The report's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.