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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:07:07+00:00 2026-06-12T06:07:07+00:00

Basically I am making a text based game (Not so much a game, more

  • 0

Basically I am making a text based “game” (Not so much a game, more of a way to improve basic java skills and logic). However, as part of it I wish to have a timer. It would count down on the time I wish from the variable to 0. Now, I have seen a few ways to do this with a gui, however, is there a way to do this without a gui/jframe etc.

So, what I am wondering is. Can you make a count down from x to 0 without using a gui/jframe. If so, how would you go about this?

Thanks, once I have some ideas will edit with progress.

Edit

// Start timer
Runnable r = new TimerEg(gameLength);
new Thread(r).start();

Above is how I am calling the thread/timer

public static void main(int count) {

If I then have this in the TimerEg class, the timer complies. However, when compiling the main in the other thread I get.

Error

Now, am I completely miss-understanding threads and how this would work? Or is there something I am missing?

Error:

constructor TimerEg in class TimerEg cannot be applied to given types;
required: no arguments; found int; reason: actual and formal arguments differ in length

Found on line Runnable r = new TimerEg(gameLength);

  • 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-12T06:07:08+00:00Added an answer on June 12, 2026 at 6:07 am

    Same as with a GUI, you’d use a Timer, but here instead of using a Swing Timer, you’d use a java.util.Timer. Have a look at the Timer API for the details. Also have a look at the TimerTask API since you would use this in conjunction with your Timer.

    For example:

    import java.util.Timer;
    import java.util.TimerTask;
    
    public class TimerEg {
       private static TimerTask myTask = null;
       public static void main(String[] args) {
          Timer timer = new Timer("My Timer", false);
          int count = 10;
          myTask = new MyTimerTask(count, new Runnable() {
             public void run() {
                System.exit(0);
             }
          });
    
          long delay = 1000L;
          timer.scheduleAtFixedRate(myTask, delay, delay);
       }
    }
    
    class MyTimerTask extends TimerTask {
       private int count;
       private Runnable doWhenDone;
    
       public MyTimerTask(int count, Runnable doWhenDone) {
          this.count = count;
          this.doWhenDone = doWhenDone;
       }
    
       @Override
       public void run() {
          count--;
          System.out.println("Count is: " + count);
          if (count == 0) {
             cancel();
             doWhenDone.run();
          }
       }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am making a Text-Based RPG Applet in Java. I am using SWING
I am making a project in Java. It is through hibernate and JMF. Basically
I'm planning on making a little game. And I'm looking for an engine. Basically
Basically I'm new to Android and don't know much about it. I'm making a
I have an object that processes text in a stateless way. It basically takes
I am having problems calling classes at run time in java Im basically making
I am trying to figure out a simple way of making a text box
I am making a 2d engine using Java based on entities. The physics and
What I am making is basically is a user profile that has a text
So I'm basically making an app that adds a count to a number and

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.