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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:56:12+00:00 2026-05-13T17:56:12+00:00

I have a java frame that I want to close it automatically after 3

  • 0

I have a java frame that I want to close it automatically after 3 or 4 seconds. I found out I must used threads. but I dont know how exactly to do it, this a dumy part of my code :

package intro;

import java.awt.*;
import java.io.IOException;
//import view.LangMenu;

public class IntroClass extends Frame {

    private int _screenWidth = 0;
    private int _screenHeight = 0;
    private int _screenCenterx = 0;
    private int _screenCentery = 0;

    //private static final String SOUND_PATH="/sounds/introSound.midi";
    public IntroClass() {
        Toolkit thisScreen = Toolkit.getDefaultToolkit();
        Dimension thisScrrensize = thisScreen.getScreenSize();

        _screenWidth = thisScrrensize.width;
        _screenHeight = thisScrrensize.height;
        _screenCenterx = _screenWidth / 2;
        _screenCentery = _screenHeight / 2;
        setBackground(Color.pink);
        Label lbl = new Label("Welcome To Dots Game. Samaneh Khaleghi", Label.CENTER);
        add(lbl);
        setUndecorated(true);
        setLocation((_screenCenterx*50)/100,_screenCentery-(_screenCentery*50)/100);
        setSize((_screenWidth * 50) / 100, (_screenHeight * 50) / 100);

        WaitClass r = new WaitClass();
        r.start();
        view.DotsBoardFrame d=new view.DotsBoardFrame();
                main.Main.showScreen(d);
    }

    class WaitClass extends Thread {

        boolean running = true;

        public void run() {
            while (running) {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }                
            }
        }
    }
}
  • 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-13T17:56:13+00:00Added an answer on May 13, 2026 at 5:56 pm

    in your frame start a new thread and pass to it your frame instance, and after a specific period of time close it.

    class MyThread extends Thread {
    
      private JFrame frame;
      //-- getters and setters for frame
    
      public void run() {
        Thread.sleep(1000); //close the frame after 1 second.
        frame.close();
      }
    
    }
    

    and in your JFrame class, in the constructor specifically put the following line of code:

    MyThread th = new MyThread();
    th.setFrame(this);
    th.start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Java Map (out of Strings and Ints) objects that I want to
I have been doing some reading and have found out that the Java Swing
I have java sdk 1.7. I've always used django/python for web development, this will
I want to add an image to a frame but I am not able
I want to provide a java application with a Microsoft Ribbon like view. After
I have the following java.util.Timer but it does not seem to execute and I
I have a main.java that has a button, when you press it, it calls
I want to write an app in java that lets two clients talk via
I have created a java program that shows a grid of buttons and labels
I have written a code in java using swing.So that i will have a

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.