Closing a JFrame without using System.exit(0)

Hello all,
I'm writting an application at the moment that uses a JFrame as an "about box" invoked when a menu item from another JFrame is selected . The about box is set to undecorated, and I have set up an Thread to handle an animation of the credits that move up slowly. I have also added into it code to play a sound file while the credits are running.
I wanted to have it so that the user can just click once anywhere on the Panel area of the about box, and that would close the about box window and stop the sound.
I can get it to stop the sound on click no problem, what I'm having issues with is closing just the about box Frame. I've used System.exit(0) but this closes the original application, which I dont want it to do. I've been looking at online example code and I've found that dispose() might work... Problem is my JFrame for the about box is initiated in the main applications JFrame under an eventListener for the menuItem 'about'. The sound file is played inside the JPanel of the about box. And the listener to close it is located in the same place ( about box JPanel ).. does anyone know how to get this frame ( initiated in main applications JFrame ) and dispose of this frame through code located in the JPanel of the about box.
I hope this is descriptive enough for you.
Please let me know if you have any questions about my question.
Many thanks,
Mark.

It seems you are asking how to find the parent frame of a Component that you know is within a frame?
You can getParent() of the component. If it is a frame (instanceof) - dispose, else check for the getParent()...
If you don't want to code it yourself use SwingUtilities.getWindowAncestor(Component) to get the Window in which the panel is.
HTH
Mike

Similar Messages

  • How to "kill" AWT Event Queue thread without using System.exit()?

    When I run my program and the first GUI window is displayed a new thread is created - "AWT-Event Queue". When my program finishes, this thread stays alive and I think it causes some problems I have experienced lately.
    Is there any possibility to "kill" this thread without using System.exit() (I can't use it for some specific reasons)

    All threads are kept alive by the JVM session. When you use System.exit(int) you kill the current session, thus killing all threads. I'm not sure, though...
    What you could do, to make sure all threads die, is to make ever thread you start member of a thread group. When you want to exit you app, you kill all the threads in the thread group before exit.
    A small example:
    //Should be declared somewhere
    static ThreadGroup threadGroup = new ThreadGroup("My ThreadGroup");
    class MyClass extends Thread {
    super(threadGroup, "MyThread");
    Thread thread = new Thread(threadGroup, "MySecondThread");
    void exit() {
    //Deprecated, seek alternative
    threadGroup.stop();
    System.exit(0);
    }

  • Closing The JFrame without using setVisible(false)

    I am using a frame for creating table "public class createTable extends JFrame" this class is being used by two panels to display the data . in a last panel where I have put two buttons "ADD" for adding records to a access table and "RETURN" to return back , while closing the "createTable" frame.
    On Clicking the "RETURN" button the code :
    setVisible(false)
    just closes the buttons in the panel whereas the original frame doesnot hides. whereas, if i use an instance of createTable:
    private createTable ctbl;
    and the have it as
    ctbl.setVisible(false);
    exception is thrown . as well as the method :
    void remove(Container con) also throws exception and does not functions smoothly.
    Can anyone please help me>>>>

    The problem is probably that you're calling setVisible on the button, not on the frame.
    If you maintain a reference to the frame then just do something like this:
    frame.setVisible(false);If you don't then you'll need to work out which frame the button belongs to:
    SwingUtilities.getWindowAncestor(this).setVisible(false);Hope this helps.

  • Using System.exit(0) in executeScript

    When using System.exit(0) in executeScript within a process, it shuts down JBoss. This happens both
    in LC ES2.5 and ADEP  10.0.1.20111108.1.309370
    I would expect that System.exit(0) simply ends the script and returns control to the process. Am I
    missing something here?
    TIA,
    Alex

    gavas_java_nov26_exception wrote:
    If i use System.exit(0) in the try block or catch block will finally block will be executed?
    try
    System.exit(0);
    catch(Exception e){
    System.exit(0);     
    finally
    System.out.println("finally!");
    To tell you the truth, What does it matter? You shouldn't be doing that anyway, at least not in a well written program.
    But, if you really want to find out, do as duffymo said, and try it. It'll only take a minute and save you the time (and embarressment) of asking here.

  • If i use System.exit(0) in the catch block will finally block executed

    If i use System.exit(0) in the try block or catch block will finally block will be executed?
    try
      System.exit(0);
    catch(Exception e){
      System.exit(0);     
    finally
      System.out.println("finally!");
    }

    gavas_java_nov26_exception wrote:
    If i use System.exit(0) in the try block or catch block will finally block will be executed?
    try
    System.exit(0);
    catch(Exception e){
    System.exit(0);     
    finally
    System.out.println("finally!");
    To tell you the truth, What does it matter? You shouldn't be doing that anyway, at least not in a well written program.
    But, if you really want to find out, do as duffymo said, and try it. It'll only take a minute and save you the time (and embarressment) of asking here.

  • Problem using System.exit()

    Hai,
    I used System.exit(1) system call in my servlet code. When this part of code is executed the whole server goes down.. i need to know if there is another smooth way of exiting code instead of System.exit().
    Thanks

    is another smooth way of exiting code instead of System.exit().System.exit() is supposed to terminate the JVM....however, your server (especially I have seen Tomcat 4.x) can hang if you call System.exit()...because there may be some active threads still running in the JVM, and server is not able to terminate them...and gets stuck.
    What is your intent? If you want to cleanly shutdown the server, then don't call System.exit(), instead, the server listens on some port for commands, connect to that port and issue a quit/exit command. For example, in tomcat looking at server.xml you could look at this element <Server port="8005" shutdown="SHUTDOWN" debug="0">. Connect to port 8005 and issue "SHUTDOWN" command to gracefully terminate the Server.
    -BJ

  • How do I exit a java program based on condition can i use system.exit

    I have java program that is called by another program that I dont have control on. My program returns a bigdecimal... but if the ordernumber is empty in my program i dont wnat to do anything.. does system.exit work in that condition... i put it int he else if ordernumber is empty condition.. but i dont think that is the right approach..

    When software module is expected to bring some result, it should bring the result, positive or negative. I think you should check what your counterpart software expects as positive or negative result. And then implement your software this way. You can use System.exit, but this call is employed usually to indicate status with the software after it's completion and not to return any resulting value.
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#exit(int)

  • Closing all JFrames without killing the application

    Is there a way I can close all JFrames without quiting the application? I have several JFrames open that I want to dispose of at the same time. Is this possible?

    If you close all the JFrames, then how does the user
    interact with the application?I think that's outside the scope of the original question, but there are a number of possibilities. To name just a few:
    1) The console
    2) The program opens a new JFrame after some time has elapsed (maybe an appointment reminder application, or an instant messenger client, for example)
    3) The program is really a server, so you don't need to see anything
    4) The program is "spyware" so it's meant to be hidden
    5) The program runs in full-screen mode part of the time (for example, a game which uses JFrames to choose options, then full-screen for game play)
    ...

  • Close window without using plug exit

    Hi experts,
    How can I close a window without using a plug exit? By implementing some javascript  in the Java code, or other options?
    Thanks in advance.
    Edited by: Alaa Cherqaoui on Nov 28, 2008 5:06 PM

    Hi ,
    You can use the "destroy" method for window.
    For example:
    you need to create WindowInstance varibale of type:
    com.sap.tc.webdynpro.services.session.api.IWDWindow
    Then inside the action that suppose to open this window you write the following:
    IWDWindowInfo windowInfo = wdComponentAPI.getComponentInfo().findInWindows("NameOfTheWindow");
    IWDWindow window = wdComponentAPI.getWindowManager().createWindow( windowInfo, true);
    window.setWindowPosition(WDWindowPos.CENTER);
    wdContext.currentContextElement().setWindowInstance(window);
    window.open();
    And inside the action that suppose to close this window write the following :
    wdContext.currentContextElement().getWindowInstance().destroy();
    Hope it's help...
    Regards,
    Shimon.

  • Close using system.exit()

    could anyone tell me to write a new program which has a button labelled 'close'. when click on 'close', it should terminate the addition program.
    import javabook.*;
    class addition
         public static void main(String args[])
              int a, b,c;
              MainWindow mainWindow = new MainWindow(); // creates a frame,mainwindow is in javabook package
              InputBox inputBox = new InputBox(mainWindow); // creates an inputbox, is in javabook package
              OutputBox outputBox = new OutputBox(mainWindow);// creates an outputbox;
              outputBox.setVisible(true);
              a= inputBox.getInteger("Enter an integer: ");
              b=inputBox.getInteger("Enter and integer: ");
              c= a + b;
              outputBox.printLine("C = %d\n",c);
    }

    closeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
    });

  • Starting and Stopping Server from Administration Console without using system ID

    Hi,
    I tried to create another user in the ACL and add it to the Administrators
    group. When I connect to the admin console using this user I receive error
    message NoAccessRuntimeException. Can anybody show me how ti configure user
    to access the console to start and stop managed server. I am using WebLogic
    6.1 SP1. TIA.
    regards,
    Rudy

    Any user added to the Admin group should be able to use the weblogic.Admin
    utility and stop the server and access the console. So if we add Rudy as a user
    to the Admin group then Rudy should be able to stop the server and also use the
    weblogic.Admin commands. however, you cannot start the server with rudy's
    password. You will require a system password for starting the server.
    Please check if the user has been added correctly to the Admin group. you can
    check this in the fileRealm.properties file:
    user.rudy=0x751cc5f18261ba5e570c19a0d2d3cc29a5c5de63
    group.Administrators=system,rudy
    hope this helps,
    Mihir
    Rudy Sutjiato wrote:
    Hi,
    I tried to create another user in the ACL and add it to the Administrators
    group. When I connect to the admin console using this user I receive error
    message NoAccessRuntimeException. Can anybody show me how ti configure user
    to access the console to start and stop managed server. I am using WebLogic
    6.1 SP1. TIA.
    regards,
    Rudy

  • How to convert date without using conversion exit?

    hi!! Guys,
         please can anybody help me how to compare date which is not in actual format
    i.e. (when comparing  BKPF-budat with TCURR-gdatu in where condition of a Select query its giving syntax error  "when you use the addition 'fOR ALL ENTRIES IN itab' the fields gdatu and it_bkpf-budat" must have the same type and the same length. its very urgent...
    thanks in advance.
    akanksha.

    try like this.
    data : year(4),
             mon(2),
    day(2).
    in itab declare field cbudat(8) type c.
    loop at itab.
    year = itab-budat(4).
    mon = itab-budat+4(2).
    day = itab-budat+6(2).
    concatenate year mon day into itab-cbudat.
    modify itab.
    endloop.
    now use select for all entries and check gdatu = itab-cbudat.
    regards
    shiba dutta

  • Is System.exit() a good call to use?

    I have a program that checks for updates in the db. If there are no updates in the database I want the program to stop. There are also many other conditions that would cause the program to stop. None of them are "Errors" so I wasn't using Exceptions to end the program The program runs from a command line or from chron job. Is it safe / OK to use System.exit() to do this?

    As you describe it, I'd say yes. System.exit() is the way to end your program.
    The danger of System.exit() is if a class you write will be reused in some other system. In that case, System.exit() could be entirely inappropriate in that context, thus preventing your class from being reusable.
    If you only call System.exit() in your main() method, you'll probably be OK.

  • Exit from a Frame without resorting to System.exit()

    This is driving me nuts.
    I've got a really simple problem, actually... I've got a Frame and I'm trying to get rid of it so my application will exit.
    Though using System.exit() seems to be the most common way to get an application to exit, I'd prefer to avoid going that route. My program uses multiple threads, and I want to give them all a chance to exit gracefully before the application exits, as opposed to terminating them all quite suddenly. All the threads monitor a boolean value, "exiting", and terminate, after some cleanup, when the variable is set. Using join() on all the threads before using System.exit() would work, except any number of threads may be created by the program, and not all of them will be accessible by the function doing the exiting!
    If I simply omit the call to System.exit(), and remove the Frame with dispose(), the threads all shut down properly, and the program appears to have exited, except the command prompt doesn't reappear until I hit Ctrl-C.
    So I looked up the docs for the dispose() method. It was slightly different than I remembered... Obviously, that method is not the way to shut down a Frame. What is?

    So I looked up the docs for the dispose() method. It
    was slightly different than I remembered...
    Obviously, that method is not the way to shut down a
    Frame. What is?The problem is that once you use some GUI, a pool of AWT threads is created and they are not shut down, not even if there is no more GUI visible.
    Look at these other threads for some explanation on this behaviour an workarounds:
    http://forum.java.sun.com/thread.jspa?forumID=5&threadID=10901
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=122569

  • Closing a gui without closing its parent

    hi,
    I am building a GUI that is opened up by another GUI. My problem is that when I close that new GUI, it closes all the other ones that I have open. It is because I am using System.exit(0);
    My question is, what do I need to do to just close the new smaller GUI that I have opened, without closing the rest?
    thanks in advance...

    Yup its because of System.exit(0);
    you need to this.dispose();

Maybe you are looking for

  • Utilization not done ! Do You want to proceed

    Hi all,          in my business sceanario, for a material the customer has to pay only VAT or CST depends on the region. no excise duty is involved and hence we are not maintaining J1ID. while taking output we are getting the message like this "Utili

  • Black screen upon waking

    Twice now since installing 10.5 my Mac has woke up with a black screen, forcing me to hold the button down and attempt rebooting several times. Is this a known problem?

  • New droid 4 owner

    I cannot find the password to enter into the wifi connection box. Can anyone help me with this?

  • File Polling in OSB

    I have a File with Fixed length format-10 First Line has 10 characters Second Line has 10 characters Third Line has 9 characters I need to ignore the Third Line as the characters are less when compared to Fixed Length How can i do this in OSB while p

  • ADF vs Content Server (Oracle UCM)

    Hallo everybody, Can anyone advise me of how to access data files on UCM in ADF fusion web application? Thanks in advance.