How do I know how many JFrames has opened ?

Hi,
I've got an application which has a main form (JFrame).
Inside this main form there are buttons which opens others JFrames.
When I close the main form I need to show how many others Jframes has opened.
How do I know how many Jframes has opened in my whole application ?
and
How can I get them ?
Can someone help me, please ?
Thanks.
wmiro.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FrameTest
    static JLabel label;
    static int
        frameCount = 0,    // number of visible frames
        frameNumber = 0;   // consecutive frame number
    public static void main(String[] args)
        label = new JLabel("frame count = 0", JLabel.CENTER);
        JButton addButton = new JButton("add frame");
        addButton.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
                makeNewFrame(++frameCount);
                label.setText("frame count = " + frameCount);
                label.repaint();
        JPanel panel = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.fill = gbc.HORIZONTAL;
        panel.add(label, gbc);
        JPanel northPanel = new JPanel();
        northPanel.add(addButton);
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(northPanel, "North");
        f.getContentPane().add(panel);
        f.setSize(175,120);
        f.setLocation(50,50);
        f.setVisible(true);
    private static void makeNewFrame(int count)
        final JFrame f = new JFrame(String.valueOf(++frameNumber));
        f.addWindowListener(new WindowAdapter()
            public void windowClosing(WindowEvent e)
                reportFrameClosing();
                f.dispose();
        f.getContentPane().add(new JLabel("frame " + frameNumber));
        f.setSize(140,70);
        f.setLocation(175 + count*40, 120 + count*80);
        f.setVisible(true);
    public static void reportFrameClosing()
        frameCount--;
        label.setText("frame count = " + frameCount);
        label.repaint();
}

Similar Messages

  • How do I know how many bytes it has read so far ?

    Like in a FileInputStream.read(byte [] b) method. How do I know how many bytes have been read into b so far ? Thanks!

    You can't directly as the method block, however it return the number of bytes that could be read. To achieve what you want I would create a wrapper class that would override read(byte[] b) and process it byte by byte with:
    int size = b.length;
    for(int i = 0; i < length; i++)
        int r = wrapped.read();
        if( r != -1 )
            b[i] = (byte)r;
            readSoFar++;
    }

  • How can I know how many processors do I need for a new SQL Server machine?

    My company intend to buy a new server and will dedicate that for SQL Server which will serve an in-house developed application.
    How can we know how many processors are enough to buy?
    I know that each SQL Server edition and version has it's different limitation of the number of processors it can support, for example SQL Server 2012 Standard Edition can support up to 4 sockets or 16 cores per SQL Server Instance, but this does not mean
    that I have to buy 4 physical CPUs. two could be enough. how can I know? 

    How can we know how many processors are enough to buy?
    I know that each SQL Server edition and version has it's different limitation of the number of processors it can support, for example SQL Server 2012 Standard Edition can support up to 4 sockets or 16 cores per SQL Server Instance, but this does not mean
    that I have to buy 4 physical CPUs. two could be enough. how can I know? 
    This is off topic question how can we answer it. We even dont have any knowledge about your application.
    Please speak to licensing specialist about servers and cores below link will give you more information.
    https://msdn.microsoft.com/en-us/library/ms143760.aspx?f=255&MSPPError=-2147217396
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
    My Technet Wiki Article
    MVP

  • How I can know if a user has the permission to read a file or not ?

    Hello,
    I have other question :
    How I can know if a user has the permission to read a file or not ?
    Smaine
    ThanK's

    I don't think common operating systems have an easy way to do that check.
    If you have a limited number of files, implement access control yourself, instead of using operating system permissions. E.g. write a configuration file that contains:
    # Syntax: "filename": "list of users who can access that file"
    somefile.txt: fred, alice, bob
    somedir/anotherfile.txt: bob, joe
    Read in the configuration file and check against it when a file is being requested.

  • How do I know if my CPU has decreased speed or what speed my cpu is running?

    I recently noticed that when running PRO app my MBP seems pretty slow unusually. I have met this occasion before . I heard that when temperture is too high , the CPU will decrease its speed to protect itself.  How do I know if my CPU has decreased speed or what speed my cpu is running?
    Thank you!
    MBP 8,2  10.6.8

    Enter in the search field of Google 'CPU speed monitors' and you should get some results.
    Ciao.

  • How do i know if my apple has a virus?

    How do I know if my apple has a virus? How do I check?

    What makes you ask? Are you having a problem that you believe is due to some kind of malware? If so, what is that problem? Describe the symptoms in detail... they're probably not due to malware, so knowing what is going on is important.
    If you're just curious about protecting yourself against malware, see my Mac Malware Guide.
    (Fair disclosure: I may receive compensation from links to my sites, TheSafeMac.com and AdwareMedic.com, in the form of buttons allowing for donations. Donations are not required to use my site or software.)

  • How do I know if my ipad has a micro sim?

    How do I know if my ipad has a micro sim?

    SIM Card
    http://i1224.photobucket.com/albums/ee374/Diavonex/Album%202/3b63179461049138651 46b933c2a9d83.jpg

  • How do I know if my imac has a web cam? I want to skype with my grandkids. Thank you

    How do I know if my iMac has a web cam on it so I can skype with my grandkids?
    Could I buy a logitech webcam for $24.98 that is on Amazon?
    Thank you

    What iMac do you Have?
    Go to About this Mac from the Apple icon top left of your finder menu window and it will tell you.

  • How do I know if the program has been downloaded to another computer or not?

    How do I know if the program has been downloaded to another computer or not? Also how do I know if it is the educational version or not?

    What exactly? Your questions don't make much sense since you failed to provide an explanation what problem you actually have, what program you actually mean and so on. That aside, edu versions are technically not different from the normal programs, just their licensing is different.
    Myleniumu

  • How do i know if my iphone has been syncronize with other device and how to remove it.?, how do i know if my iphone has been syncronize with other device and how to remove it.?thanks

    how do i know if my iphone has been syncronize with other device and how to remove it.?, cuz. I had found out that one of my co-work who was updatinng my phone was syncronizing to his name..in this case my photos is been syncronize to his acount.pls help...
    thanks

    Hey Cherielly,
    Thanks for using Apple Support Communities.
    Since you are having an issue with syncing to a different apple id. You may want to make sure you are signing in with the correct apple id.
    iOS: Sign in with a different Apple ID in the iTunes Store, App Store, and iBooks Store
    http://support.apple.com/kb/ht1311
    Have a nice day,
    Mario

  • HT201240 how do I know if my computer has an optical drive?

    how do I know if my computer has an optical drive?

    An optical drive is a CD or DVD drive. They are standard on all MacBook Pros and most other Macs released in the last ~15 years.
    (65628)

  • How do I know if Mountain Lion has installed properly?

    How do I know if Mountain Lion has installed properly?

    I can only guess that the install process was interrupted, maybe after the files were extracted but before the install, maybe on the reboot?
    If it was dome ot would say version 10.8.  And you would have the reminder and notes apps as well, also an easy thing to check.

  • User Profile Services:How get to know how many user are using my site.

    Hi,
    User Profile Services:How get to know how many user are using my site.
    Recently i have done migration sharepoint 2010 to sharepoint 2013,I did not migrate USer profile services because less user are using user profile here,but i need to know how many few uer are using my site for data store.
    Is any why we can get to know  user name who are using my site document library and other things.
    Hasan Jamal Siddiqui(MCTS,MCPD,ITIL@V3),Sharepoint and EPM Consultant,TCS
    |
    | Twitter

    Fallowing command shows only count of my site user ,I need to know how many upload data on my site
    Hasan Jamal Siddiqui(MCTS,MCPD,ITIL@V3),Sharepoint and EPM Consultant,TCS
    |
    | Twitter

  • TS1591 how do i know if my computer has usb 2.0

    how do i know if my computer has usb 2.0

    If your computer is from the past 10 years, it is very, very likely that it has at least USB 2.

  • Hi, for Iphone tips page "see when a message was sent " , then how do I know that the message has been read?

    Hi,
    for Iphone tips page "see when a message was sent " , then how do I know that the message has been read? Thanks  

    Hi Bhavesh,
    Please see my replies inline:
    > 1. If i remember your ealier thread correct also, I
    > would suggest that you drill down in Where Did the
    > Error Occur. Instead of no restriction, select
    > Adapter Engine and also your Corresponding Adapter
    > and then trigger the error message and check if the
    > alert is triggered.
    When I click on "Where did the error occur" -> "Adapter Engine", I do not have a choice of errors from the dropdown. I only see one option "*".
    Is this right?
    > 2. ><i>When I click on "Alert Inbox" ->
    > "Subscription", I get a message "The table does not
    > contain any entries". Is this correct?</i>
    >
    > Yes this is correct. You have defined in your alerts
    > as the option as FIED RECIPIENTS. You also have
    > options like Reciepients via User Role and
    > Subscription Authorization in ALRTCADTDEF.
    >
    I see.
    I've also managed to overcome this problem by selecting "Subscription Authorization" in the Alert Category Definition page, and entering SAP_XI_MONITOR as one of the roles.
    After that, I am able to see a the alert category defined. By default it's already subscribed, because I'm using the same user - PISUPER.
    I saw in another post that the option "Suppress Multiple Alerts of this Rule" should be left unchecked. I tried that, but I still do not see any alerts raised in ALRTDISP.
    What did I miss?
    Please help.
    Thanks.
    Ron

Maybe you are looking for

  • Exporting with precise length?

    Hey everyone, Relatively new to Logic, but not a total DAW dummy. The problem I'm having is kind of infuriating but otherwise I love the software. Basically, I am building 4- and 8-bar loops in Logic at a tempo of 103 BPM. I have uploaded my samples

  • Can not detect sound blaster c

    ok, i've read all the posts and nothing helped. I have an audigy gamer and also audigy 2 zs plat. pro both i get the message : "s on your system please make sure your cards installed correctly before running this program now exiting" My heads about t

  • Necessary to see green check-mark (Update Successful) during Airport Firmware Update?

    I had just taken the leap of faith and decided to update my current workhorse Airport Extreme to 7.6.1 fro 7.6. It downloaded and ran successfully all the way to the rebooting of the router. However, the computer I was running my Airport Utility on d

  • XI problems BP not created

    Hi experts I am using standard scenario MM-SUS and all is configured and working, but when I send vendor from R/3 to SUS not errors are find in SXI_MONITOR, SM58 and SMQ2, but for some reason the Business Partner is not cretaed in SUS. Please someone

  • Can SQL server 2014 instance be introduced into SQL server 2012 clustering

    Hello, everyone, We have SQL server clustering set up in place (it is actually windows clustering), I am wondering if it is possible to introduce SQL server 2014 instance into this clustering. Please share us your thoughts and experiences. Thanks