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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:18:50+00:00 2026-06-03T23:18:50+00:00

My program will alert users when data (stock name & price) in the database

  • 0

My program will alert users when data (stock name & price) in the database matches with the data (stock name and price) from Yahoo Finance. With the help of HarryJoy i’m able to implement a pop up notification.

The problem now is, all the functions only works on the last frame (YHOO). It will not dispose() after 5 seconds, or when I click the closeButton. Thanks!

PopUp

    if (stockPriceDB == popStockValue)
    {                       

        String header = "Stock: "  + stock.getTicker() + " is now @ " +  stock.getPrice();          
        String message = "";

        popUpFrame = new JFrame();
        popUpFrame.setSize(320,90); 
        popUpFrame.setUndecorated(true);                                    
        popUpFrame.getContentPane().setLayout(new GridBagLayout());

        GridBagConstraints constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.weightx = 1.0f;
        constraints.weighty = 1.0f;
        constraints.insets = new Insets(5, 5, 5, 5);
        constraints.fill = GridBagConstraints.BOTH;
        JLabel headingLabel = new JLabel(header);

        ImageIcon headingIcon = new ImageIcon("images/alert.gif");          
        headingLabel.setIcon(headingIcon);          

        popUpFrame.getContentPane().add(headingLabel, constraints);
        constraints.gridx++;
        constraints.weightx = 0f;
        constraints.weighty = 0f;
        constraints.fill = GridBagConstraints.NONE;
        constraints.anchor = GridBagConstraints.NORTH;                          

        closeButton = new JButton(); 

        closeButton = new JButton(new AbstractAction("x") 
        {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(final ActionEvent e) 
            {
                popUpFrame.dispose();
            }
        });

        closeButton.setMargin(new Insets(1, 4, 1, 4));
        closeButton.setFocusable(false);
        popUpFrame.getContentPane().add(closeButton, constraints);
        constraints.gridx = 0;
        constraints.gridy++;
        constraints.weightx = 1.0f;
        constraints.weighty = 1.0f;
        constraints.insets = new Insets(5, 5, 5, 5);
        constraints.fill = GridBagConstraints.BOTH;                 

        JLabel messageLabel = new JLabel(message);  
        popUpFrame.getContentPane().add(messageLabel, constraints);
        popUpFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        popUpFrame.setVisible(true);

        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Insets toolHeight = Toolkit.getDefaultToolkit().getScreenInsets(popUpFrame.getGraphicsConfiguration());
        popUpFrame.setLocation(screenSize.width - popUpFrame.getWidth(), screenSize.height - toolHeight.bottom - (popUpFrame.getHeight() * (x+1)));

        new Thread()
        {                           
        public void run() 
            {
                try 
                {
                    Thread.sleep(5000); 
                    popUpFrame.dispose(); 
                } 
                catch (InterruptedException e) 
                {
                    e.printStackTrace();
                }
            };

        }.start();
    }
}
  • 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-06-03T23:18:52+00:00Added an answer on June 3, 2026 at 11:18 pm

    I suspect that the problem you are getting is that you are passing, to an external code (a different thread in this case), a variable of popUpFrame which you then assign new object every instance of the loop.

    This approach is susceptible to errors as you are loosing the reference you passed. Because you are overwriting it every time you create a new object.
    Therefore, I think you might be only able to close to latest one.

    To avoid something like this a variable you pass to an external code should always be final or when instantiating an external process store a reference to it inside the external code.

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

Sidebar

Related Questions

My program will alert users when data (stock name & price) in the database
I have a search program that will be looking at a database from a
As we all know Java program will start executing from the public static void
I have a program that will let me manage users on our terminal server
My program will sometimes be launched from another program. If that's the case, I
I created a server program that will be started as root. After it is
I have a java program that will work with a variety of Java Beans.
when I ran a program which will cause the segmentation fault as root user
I am compiling my program that will run on linux gcc 4.4.1 C99. I
I'm writing a program which will use scan conversion on triangles to fill in

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.