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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:55:24+00:00 2026-06-18T22:55:24+00:00

I am trying to print a statement repeatedly using Swing Timer but the statement

  • 0

I am trying to print a statement repeatedly using Swing Timer but the statement doesn’t gets printed !

What’s the mistake I am making ?

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Timer;

    public class SwingTimer implements ActionListener {

        Timer timer;

        public static void main(String[] args) {
            SwingTimer obj = new SwingTimer();
            obj.create();
        }

        public void create() {
            timer = new Timer(1000, this);
            timer.setInitialDelay(0);
            timer.start();
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Hello using Timer");
        }    
    }
  • 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-18T22:55:25+00:00Added an answer on June 18, 2026 at 10:55 pm

    The javax.swing.Timer probably starts as a daemon thread: it doesn’t keep the jvm alive, your main ends, the jvm exits. It post the timer events to the GUI event queue which starts when the first dialog or frame is made visible.

    You have to create a JFrame, and make it visible or use the java.util.Timer if you don’t need windowing system at all.

    The following code shows how to use java.util.Timer:

    import java.util.Timer;
    import java.util.TimerTask;
    
    public class TimerDemo extends TimerTask {
    
       private long time = System.currentTimeMillis();
    
       @Override public void run() {
          long elapsed = System.currentTimeMillis() - time;
          System.err.println( elapsed );
          time = System.currentTimeMillis();
       }
    
       public static void main( String[] args ) throws Exception {
          Timer t = new Timer( "My 100 ms Timer", true );
          t.schedule( new TimerDemo(), 0, 100 );
          Thread.sleep( 1000 );              // wait 1 seconde before terminating
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to print to a file using the following statement Print #1,
I have a java code where i am trying to print a statement by
I'm trying to create a print statement that can print any type. I want
I am trying print a vaules retrived from select but, I could not find
I'm trying to add a print statement to all functions in a python script
I am trying to print the following statement: print false . \n . true
I'm trying to print a simple table in python, but none of the previous
I am having real problems trying debug my code to malfunctioning print statements. I
Im trying print Excel file data on a page. To do it i used
Im trying to print the realtime output based on user input for a search.

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.