Closing One JFrame instead of All JFrames?

Hello everyone,
I am developing a program using Sun's Forte community edition V3.0, this is for an assignment and I have chosen Java and Swing instead of the Recommended MS Access. Grin (You got to love a challenge.)
I have a menu class that allows users to create instances of other classes by clicking various buttons representing options.
When the user clicks a button a new class instance is created allowing the user to interact with the system.
//-- Action in response to a buton click. This calls an instance of a working
//-- class.
private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {
        final JFrame fs = new SRemClassEntryFr();
        fs.setBounds(150, 150, 530, 398);
        fs.setVisible(true);
        fs.setTitle("SRemClassEntry");
        fs.setDefaultCloseOperation(HIDE_ON_CLOSE);
        fs.getContentPane().setBackground(java.awt.Color.cyan);
        fs.addWindowListener(new WindowAdapter(){
            public void windowClosed(WindowEvent e){
                System.exit(0);
//-- The starting class of the application. A simple class that calls other
//-- classes based on users selecting menu items represented as buttons
public static void main(String args[]) {
        //-- new AdminMainMenuFr().show();
        final JFrame f = new AdminMainMenuFr();
        //f.setContentPane(f.getContentPane());
        f.setBounds(150, 150, 620, 560);
        f.setVisible(true);
        f.setTitle("Admininistrator Main Menu");
        f.getContentPane().setBackground(java.awt.Color.cyan);
        f.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        f.addWindowListener(new WindowAdapter(){
            public void windowClosed(WindowEvent e){
                System.exit(0);
    }My application is behaving itself as intended, it does have a major problem and that is...
On selecting an operation from the Administrator menu, I am able to use and interact with that specified object instance. Unfortunately when I close the open object, it not only closes the said object but the underlying Administrator menu object also.
Does anyone have any ideas on how I should be doing this?
Thanks in advance
Mark.

fs.setTitle("SRemClassEntry");
fs.setDefaultCloseOperation(HIDE_ON_CLOSE);
fs.getContentPane().setBackground(java.awt.Color.cyan);
fs.addWindowListener(new WindowAdapter(){ 
public void windowClosed(WindowEvent e){
System.exit(0); /// here is the problem
});you say when the SRemClassEntry is closed, "exit the program" , (System.exit(0);)
hope that helps

Similar Messages

  • Closing One jframe opening another??

    I have created a number of classes which each contain 1 jFrame. Each of these class files are located in separate folders relating to what they do ie.. login, mainwindow, contact etc.
    My problem is that after i login using the login jFrame i want it to switch to the mainwindow jFrame but i cannot seem to be able to do this unless the mainwindow class is in the same folder as the login class.
    I want to be able to keep everything in separate folders for maintence purposes otherwise things will get very messy.
    Any help would be greatly appreciated.

    U:\GUI\Login\login.java:221: cannot resolve symbol
    symbol : class mainWindow
    location: class login
                             mainWindow MW = new mainWindow();
    ^
    U:\GUI\Login\login.java:221: cannot resolve symbol
    symbol : class mainWindow
    location: class login
                             mainWindow MW = new mainWindow();
    ^
    Note: U:\GUI\Login\login.java uses or overrides a deprecated API.
    Note: Recompile with -deprecation for details.
    2 errors
    Tool completed with exit code 1
    This is just because it cant find the required class files. I just want to know how to point to these files which are in another folder.
    Oh ya if you know what that deprecation thing is about let me know. It occurs in the line of code String password = jPasswordBox.getText();

  • CS5 problem Adjustment layers only affect one layer instead of all

    I am getting this problem with Photoshop CS5 I think one of the settings got changed by accident but for some reason I cannot get any of the adjustment layers Levels,Curves etc to affect all layers under them. Instead it just changes the brightness of one layer only which is the one just below the adjustment layer but not all of the others. I use Photoshop for Digital art and I was all of the layers under the adjustment to change the look of the full image instead of just one layer. Is there any way of fixing this problem? I dont know what to do

    I think I know what the problem may be:
    When you're adding a new adjustment layer the following checkbox is coming on by default:
    You probably changed the default for this.  Here's how to change it back:
    Make the Adjustments panel visible by clicking the Window - Adjustments menu.
    Click the little fly-out menu icon at the upper-right.
    Clear the Clip To Layer checkbox.
    -Noel

  • Opening Thunderbird once gets me several identical thunderbird pages in succession. Closing one of them closes all.

    When I double click on thunderbird to open my mail program, I get 2 mail home pages in succession. When I close one of them, both close.

    Firefox should have no impact on Thunderbird as it is installed in a separate place and uses a Profile separate from ones used with Thunderbird.
    This can be a Thunderbird issue and since this is a Firefox forum there is generally not many here that do Thunderbird support.
    ex: http://forums.mozillazine.org/viewtopic.php?f=31&t=2622605

  • More than one JFrame and disposing them - memory leaks...

    Hi,
    I'm opening more than one JFrame from my application. The main JFrame is a standard one and each new one is a little bit different:
    class MyFrame extends JFrame {
      public MyFrame() {
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        new MyThread().start();
      private class MyThread extends Thread {
        public void run() {
    }The problem is the when I use this inner thread and then close the frame, no resources are freed (of course I am sure this inner thread is no longer running and then I close the frame). Each resource is stored only locally.
    I tried to add the finalize() method, run time to time System.gc() and System.runFinalization() from the main thread and that is what I observed:
    - the finalize() of the MyThread class sometimes is invoked,
    - the finalize() of the MyFrame class is never invoked.
    When I throw away running this inner thread - finalize() of MyFrame is invoked.
    Is there any general rule for creating such multithreaded solutions with swing components which I don't know? Or there must be something weird in my implementation of MyThread? One more info - when closing JFrame isAlive() of MyThread returns false (I have tested it using window listener).
    milt

    Since your inner class is non-static, it maintains an implicit reference to
    the enclosing class. That would keep it from getting collected while the
    thread is running. Unless closing the Frame forces the thread to
    stop somehow, the thread will keep running to completion.
    finalize() is not a reliable source of data, sadly.

  • How can you delete all the e mail at one time instead of one at a time?

    How can you delete all the e mail at one time instead of one at a time?

    you'd have to do it from the computer,

  • How to make only one JFrame active at a time !!!

    Hy, I have created a JFrame and I have placed a
    JPanel in it. I also have a JButton "New" on the
    JPanel. When I click on the "New" Button, another JFrame
    appears. But I want ONLY one JFrame to be appeared
    at a time. That is when a JFrame appears on the JPanel,
    I should not be able to add another one.
    If it is not possible to do this with JFrame, then how to do
    it with a JDialog
    How to do this.
    thanks

    You can declare a boolean variable in your class and set it to true if you open a window. Next time when you click the NEW button, check whether that boolean value is true or false. If true then don't open a new window. Also when u close the frame window, set the boolean value to false.

  • Adobe InDesign CC 2014 Custom Panel Built With Extension Builder - Problem: Can't tab from one entry field to the next; Hitting tab instead hides all palettes; Is there a fix? This didn't happen in Adobe Indesign CC

    Adobe InDesign CC 2014 Custom Panel Built With Extension Builder - Problem: Can't tab from one entry field to the next; Hitting tab instead hides all palettes; Is there a fix? This didn't happen in Adobe Indesign CC

    This is planned to be fixed in the next release.

  • How do I delete all my Contacts in ONE GO instead of one by one and add them back again refreshed?

    How do I delete all my CONTACTS IN ONE GO instead of ONE BY ONE and add them again renewed?

    There is an option, under Advanced, on the Info Pane in iTunes to replace all contacts on your phone with what's on your computer for the next sync only. So, edit everything on your computer & use that method.

  • I recently rebuilt my iphoto 09 library and now all the pics are in one folder instead of events.  How do I get 20,000 pics back into the correct events?

    I recently rebuilt my iphoto 09 library and now all the pics are in one folder instead of events.  How do I get 20,000 pics back into the correct events?
    I have a macbook pro Version 8.1.2 and I am using Iphoto 09
    I rebuilt library because many pics were black and now they are in one folder labeled "Recovered"

    Do you have the original iPhoto Library (before you rebuilt it)?
    If so, I suggest you rebuild it using iPhoto Library Manager, a program you can download. It does a better job of rebuilding. It also leaves your original intact and makes the rebuilt Library a new file (package).
    If you don't have the original (say, from a backup), then you should probably first back up the library that you have before trying anything.
    After making a backup of it, look along the left side, you will see Events and Photos. Is there anything in either of those areas?
    If not, it sounds like all your photos were recovered and put in Recovered during the rebuild. iPhoto Library Manager might do a better job with this. In any case, if there are no photos in Events or in Photos, try selecting ~ 5 photos in Recovered and drag them to Photos. Do they then show up there with the correct dates? Do they also show up in Events after doing that? I am suggesting just a few photos before you try it with 20,000.
    If the photos inside your "recovered" area are also in Photos, then don't do the above steps. I'm not sure I can help you if your 20,000 photos are in Photos but not Events. I'd try iPhoto Library Manager instead with its better rebuild.
    If the 5 photos experiment works, then I would try it with ~ 200 photos at a time, going through your entire collection. You'll need to do this about 10 times if you really have 20,000 photos. Remember, don't do this if the "recovered" photos are already in "Photos."

  • How sholud we call one jframe class from another jframe class

    Hi
    In my application i am calling one jframe class from another jframe clas.
    how sholud we make previous jframe inactve when another jframe is invoked?(user sholud not able to make any changes on on parent jframe window when another jframe is invoked)
    Pls reply.

    Sorry for me it is not possible to change existing code,
    pls suggest me any other solution so that i can inactive parent jframe when child jframe execution is going on.

  • How can I (and why is it neccessary) unite all songs to the albums  covers they belong to. Some are listed multiple times, instead of all under the one album artwork. Example: All Things Must Pass by George Harrison. Album picture is there, square, and tr

    I really must protest. iTunes does a terrible job, at least mine always has it messed up some how for some reason. like for instance. There are multiple listings of Album covers or empty sqyartes with art work moissing, and only some songs listed on each listing, instead of all the dangf song (tracks) that are on that disc, listed there as on that disc, you understand me. its mostly all spread out, not where it should nbe. Why is that and how can i easily make it the way it is supposed to be, all tracks belonging to the particulart album listed under that albums picture , album cover art woirk.? Why is it doing this. Whats the magic button to straighten this mess out. And duplicates, i thought they were supoposed to be elliminated. not so. Help. [email protected]...thjanks.

    My daughter has had her Razr for about 9 months now.  About two weeks ago she picked up her phone in the morning on her way to school when she noticed two cracks, both starting at the camera lens. One goes completely to the bottom and the other goes sharply to the side. She has never dropped it and me and my husband went over it with a fine tooth comb. We looked under a magnifying glass and could no find any reason for the glass to crack. Not one ding, scratch or bang. Our daughter really takes good care of her stuff, but we still wanted to make sure before we sent it in for repairs. Well we did and we got a reply from Motorola with a picture of the cracks saying this was customer abuse and that it is not covered under warranty. Even though they did not find any physical damage to back it up. Well I e-mailed them back and told them I did a little research and found pages of people having the same problems. Well I did not hear from them until I received a notice from Fed Ex that they were sending the phone back. NOT FIXED!!! I went to look up why and guess what there is no case open any more for the phone. It has been wiped clean. I put in the RMA # it comes back not found, I put in the ID #, the SN# and all comes back not found. Yet a day earlier all the info was there. I know there is a lot more people like me and all of you, but they just don't want to be bothered so they pay to have it fix, just to have it do it again. Unless they have found the problem and only fixing it on a customer pay only set up. I am furious and will not be recommending this phone to anyone. And to think I was considering this phone for my next up grade! NOT!!!!

  • How can I get websites to open in free-standing windows instead of all stacked up in one window?

    If I have a window open and click on a link to open another, they all stack up in one window instead of opening a new free-standing window. How can I change this?

    I am male, so in your eyes I am a god. I'm glad I could help!!

  • Multiple windows... closing one exits the app!

    Hi, I've created a simple web browser where the class with the main method is supposed to create some windows and have the app exit when the last window is closed. The problem is that when I go to close just one of the windows all the windows close and the application exits.
    Any help is appreciated! :)
    Browser.java
    package browser.Browser;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    public class Browser {
         public static void main(String[] args) {
             BrowserFrame f1 = new BrowserFrame();
            f1.setVisible(true);
            BrowserFrame f2 = new BrowserFrame();
            f2.setVisible(true);
        /*public void newWindow() {
              BrowserFrame f = new BrowserFrame();
            f.setVisible(true);
    BrowserFrame.java
    package browser.Browser;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    import java.net.*;
    import java.io.*;
    public class BrowserFrame extends JFrame implements
                                                           ActionListener,
                                                           HyperlinkListener {
         Color menuColor = new Color(220, 220, 220);
         URL url;
         JTextField URLBar;
         static JButton goButton;
         static JEditorPane ViewArea;
         * The constructor.
         public BrowserFrame() {
             //look and feel
             try {
                 UIManager.setLookAndFeel(
                      UIManager.getSystemLookAndFeelClassName());
                 Toolkit.getDefaultToolkit().setDynamicLayout(true);
              catch (ClassNotFoundException e) {/*do nothing*/}
              catch (InstantiationException e) {/*do nothing*/}
              catch (IllegalAccessException e) {/*do nothing*/}
              catch (UnsupportedLookAndFeelException e) {/*do nothing*/}
             //create the controls
             try {
                  url = new URL("http://www.google.com");
             }catch(MalformedURLException e) {/*do nothing*/}
             URLBar = new JTextField();
             goButton = new JButton("Go");
              ViewArea = new JEditorPane();
              JPanel upperPanel = new JPanel();
             JPanel mainPanel = new JPanel();
             upperPanel.setLayout(new BorderLayout());
             mainPanel.setLayout(new BorderLayout());
              //set the control's properties
              goButton.setSize(new Dimension(12, 20));
              URLBar.setText(url.getProtocol() + "://" + url.getHost() + "/");
              URLBar.setBorder(BorderFactory.createEtchedBorder());
              ViewArea.setEditable(false);
              //Event handlers
              goButton.addActionListener(this);
              URLBar.addActionListener(this);
              ViewArea.addHyperlinkListener(this);
              //The scrollPane is for the ViewArea
             JScrollPane scrollPane = new JScrollPane(ViewArea);
             //add controls to the panel(s)
             mainPanel.add(upperPanel, BorderLayout.NORTH);
              upperPanel.add(URLBar, BorderLayout.CENTER);
              upperPanel.add(goButton, BorderLayout.EAST);
             mainPanel.add(scrollPane, BorderLayout.CENTER);
             //frame setup
             setJMenuBar(CreateJMenuBar());
             getContentPane().add(mainPanel);
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             setSize(600, 450);
             URLBar.setSize(getWidth() - goButton.getWidth(), 20);
             setVisible(true);
             connectToURL();
        //actionListener methods
        public void actionPerformed(ActionEvent e) {
              if(e.getActionCommand().equals("Exit")) {
                   dispose();
                   //System.exit(0);
              else if(e.getSource() == goButton) {
                   try {
                       url = new URL(URLBar.getText());
                       connectToURL();
                      }catch (MalformedURLException err) { //try prefixing "http://"
                           try {
                                url = new URL("http://" + URLBar.getText());
                                connectToURL();
                           catch(MalformedURLException e2) {/*do nothing*/}
              else if(e.getSource() == URLBar) {
                   System.out.println(URLBar.getText());
                   try {
                        url = new URL(URLBar.getText());
                        connectToURL();
                   catch (MalformedURLException err) { //try prefixing "http://"
                        try {
                                url = new URL("http://" + URLBar.getText());
                                connectToURL();
                           catch(MalformedURLException e2) {/*do nothing*/}
         public void hyperlinkUpdate(HyperlinkEvent e) {
              if (e.getEventType()==HyperlinkEvent.EventType.ACTIVATED) {
                   if (e instanceof HTMLFrameHyperlinkEvent) {
                        ((HTMLDocument)ViewArea.getDocument()).processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent)e);
                   else {
                        try {
                             ViewArea.setPage(e.getURL());
                             URLBar.setText(ViewArea.getPage().toString());
                        catch(IOException ioe) {
                             System.out.println(ioe);
         public void connectToURL() {
              try {
                   URLBar.setText(url.toString());
                   ViewArea.setPage(url);
              catch(IOException e) {
                   URLBar.setText("failed.");
        public JMenuBar CreateJMenuBar() {
            JMenuBar menuBar = new JMenuBar();
            menuBar.setBorderPainted(false);
            JMenu menu = new JMenu("File");
            menu.setMnemonic(KeyEvent.VK_F); //for navigating the menu
            JMenuItem menuItem;
            menuBar.setBackground(menuColor);
            menu.setBackground(menuColor);
            menuBar.add(menu);
            //the menuitems for "File"
            menuItem = new JMenuItem("Exit", KeyEvent.VK_X);
            menuItem.getAccessibleContext().setAccessibleDescription("Exit the program");
            menuItem.setBackground(menuColor);
            menuItem.addActionListener(this);
            menu.add(menuItem);
            //the menuitems for "Edit"
            menu = new JMenu("Edit");
            return menuBar;
    }

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);I don't know much of Swing but it might have something to do with this line. You might take a look at the Swing tutorials and the API docs.

  • Closing one GUI and opening another?

    Hi guys,
    (I didnt really know which forum to post this in, so apologies in advance if this is the wrong one).
    I have created a login screen for a system, LoginScreen.java, which accepts a username and password and checks these on the server for validity. This all works fine.
    Once an account is accepted as valid I would like for the login screen to close, and the actual main GUI, Client.java, to open.
    Can anyone tell me the code for doing this? (closing one GUI and opening another).
    Please ask if you need more information on my code.
    Many thanks!

    You can make the Client.java as your main program then just call the LoginScreen.java.
    import javax.swing.*;
    public class Client extends JFrame {
    public static void main (String[] args) {                     
         Login log = new Login();
         log.show();     
    // Here you can put validation if the user is valid before displaying the main GUI
    // If valid user
         Client clt = new Client();
    clt.show();     
    // } else {
    // System.exit(0);
    public Client() {
         super("Client Java");
         setSize(400, 300);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    class Login extends JFrame {
    public Login() {
         super("Login Java");
         setSize(200, 300);
    }

Maybe you are looking for

  • How do I back up photos and video in my iPad?

    Just bought my iPad Air. I installed iTune in my laptop (PC) and would like to back up all the photos and video in my iPad to my computer so that I can free up space. I cannot find way to do it within iTune application. Can you suggest how to backup

  • Airport Extreme 802.11n gone after firmware update

    Started Airport Utility earlier today, just to check a password. An Apple window came up offering new firmware, 7.1.1, I think. I usually accept these offers without thought, so I let the update run. Now Airport Utility cannot detect the Airport Extr

  • Premiere CS6 Save Files Ballooning in Size

    Opened up a verison of a CS6 project I have been working on for a while, changed absolutely nothing after opening it, and did a  "save as." The save-as project goes from the original 75mb to over 1gb - after touching nothing in the project! What's go

  • BO fails to display cloned reports with DATE_TIME data in View mode

    Problem: We create a table using Rebean API. The table contains cells displaying DATE_TIME data (Detail). The cellu2019s formula is correct and the Applet shows the data alright. But when in view mode, there stand u201CINPUT_DATE_TIMEu201D text. If w

  • T500 Standby Problem

    I recently purchased a T500 to replace my old T42P and am having a problem with the power saving settings that I can't solve.  For reasons that are unclear to me, when left idle, the machine will go into standby mode (even when it is using power from