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

  • Home
  • SEARCH
  • 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 6619465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:58:20+00:00 2026-05-25T20:58:20+00:00

So in my java class we have a homework assignment to use System.currentTimeMillis to

  • 0

So in my java class we have a homework assignment to use System.currentTimeMillis to display the amount of time between clicks. I’ve tried and tried but it isn’t working. Here’s my code.

 1 /* Matthew Caldwell
 2  * September 21, 2011
 3  * Homework #4: Problem 5.8.1 pg. 149
 4  * Program that displays the amount of time that passed
 5  * between two mouse clicks. Nothing is displayed
 6  * on the first click, then each successive click will 
 7  * display how much time passed between that click and 
 8  * the previous one. 
 9  */  
10  
11 import objectdraw.*; 
12 import java.awt.*; 
13  
14 public class ElapsedTimeClient extends WindowController { 
15    
16   public static void main(String[]args) { 
17     new ElapsedTimeClient().startController(800,500);
18   }
19 
20   private Text title,result;
21   private double count = 0;
22 
23   public void begin() {
24     
25     // Set up the title and result
26     title = new Text("CLICK COUNTER",
27                      canvas.getWidth() / 2,
28                      20, canvas);29     title.move(-title.getWidth() / 2, 0);
30     result = new Text("", canvas.getWidth() / 2, 40, canvas);
31 
32   }
33 
34   public void onMouseClick(Location p) {
35 
36     double timerS=0;
37 
38     if(count == 0) {
39       timerS = System.currentTimeMillis();
40     } else {
41       result.setText("The time between clicks was " +
42                      (System.currentTimeMillis() - timerS)/1000 +
43                      " seconds.");
44       timerS = System.currentTimeMillis();
45     }
46 
47     count++;
48 
49   } 
50  
51 }

I don’t really want anyone to completely tell me how to do it but I just need a little guidance. What am I doing to make this wrong?
The code all compiles and runs just fine but when I click instead of giving me the time that elapsed between clicks it’s giving me a big long number that never changes. It’s telling me 1.316639174817E9 almost every single time.

  • 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-25T20:58:20+00:00Added an answer on May 25, 2026 at 8:58 pm

    Firstly, system time in millis should be represented as a long, not a double.

    Secondly, you need to make the variable that holds the time since the last click (timerS) an instance variable, it’s currently method local and so reset every time.

    In short, change:

    double timerS=0;
    

    from being a local variable, to an instance variable, and a long:

    public class ElapsedTimeClient extends WindowController { 
    long timerS;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We've gotten a homework assignment in Java, which relates to inheritance. I don't have
Is there a way for a Java class to have an awareness of its
Referring here A is a precompiled Java class (I also have the source file)
If I have a java class which is package-private (declared with class, not public
So we have a java class with two ArrayLists of generics. It looks like
I have a java class: it.eng.ancona.view.RuoliView$TabElaborazioneFattureValidazione$ElencoDettaglioElaborazioneFattureValidazione$RigaElencoDettaglioElaborazioneFattureValidazione It's so long for multiple inner class. If
I have a java class which fires custom java events. The structure of the
I have a java class that applies an xslt to all xml files in
I have the following java class with the JAXB @XMLRootElement annotation @XmlRootElement(name=ClientData) public class
I have a simple Java class that I need to serialize to be stored

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.