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 6335863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:56:19+00:00 2026-05-24T18:56:19+00:00

How can I close Java GUI without System.exit ? When I use dispose() the

  • 0

How can I close Java GUI without System.exit? When I use dispose() the GUI does close, but after that it won’t start again? I am using GUI to automatically grab and write an image from camera to disk, so I need to repeat this action each time when I start GUI. Later, I want to connect this GUI to start in MATLAB.

public class MainWindow {
    int fs_c = 1;
    MainWindow() {
        JFrame main_f = new JFrame("GUI");
        main_f.getContentPane().setLayout(new BorderLayout());
        main_f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        main_f.getContentPane().add(tabPane1, "Center");

        //main_f.setSize(500, 620);
        main_f.pack();
        main_f.setVisible(true);
        commandVal = 0;

        while (true) {
            if (fs_c == 1) {
                commandVal = 5;
            }
            if (commandVal == 5 || commandVal == 6) {
                cImage.sendFrame(0);
                JFileChooser save_d = new JFileChooser();
                File saveFile = save_d.getSelectedFile();
                cImage.writeImage(saveFile + ".jpg");
                fs_c = 0;
                main_f.dispose();
            } else if (commandVal == -1) {
                stopCameraStuff();
            }
        }
    }
}
  • 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-24T18:56:20+00:00Added an answer on May 24, 2026 at 6:56 pm

    You should also break the while loop somehow so that the method can be completed and return to the caller.

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

Sidebar

Related Questions

Does anybody know how I can close all modal dialogs created by Dojo ?
Can anyone provide me an example of how to use WM_CLOSE to close a
I have been writing a small java application (my first!), that does only a
I can't understand why Java's HttpURLConnection does not follow an HTTP redirect from an
Anyone that could help me with the java.util.Scanner class? I can't figure out exactly
Possible Duplicate: How to programmatically close a JFrame I am developing a java GUI
I'm new at Java GUI and I'm trying to make a program that shows
I'm trying to make a GUI in java, but JMenuBar has been giving me
I get errors when viewing forms and there are not any. I can close
How can I close any Office 2007 running application like Word,Excel,Outlook before installing an

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.