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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:27:25+00:00 2026-05-27T06:27:25+00:00

I used the following program to get the clock.What it turned out to be

  • 0

I used the following program to get the clock.What it turned out to be is a static clock ? Why is it so ?

import java.util.*;
import java.awt.*;
import javax.swing.*;

class tester {

    JFrame fr = new JFrame();
    JPanel p = new JPanel();
    JLabel l = new JLabel();
    Date d = new Date();
    GregorianCalendar gc = new GregorianCalendar();

    tester() {
        p.setBackground(Color.red);
        l.setVisible(true);
        p.add(l);
        fr.add(p);
        fr.setSize(200,200);
        fr.setVisible(true);
        startClockThread();
    }

    public void startClockThread() {
        Runnable r = new Runnable() {
            @Override
            public void run() {
                startClock();
            }
        };
        new Thread(r).start();
    }

    public void startClock() {
        l.setVisible(true);  
        while(true) {
            l.setText(gc.get(gc.HOUR) + ":" + gc.get(gc.MINUTE) + ":" + gc.get(gc.SECOND));
            System.out.println(gc.get(gc.SECOND));
        }
    }

    public static void main(String args[]) {
        new tester();
    } 
} 
  • 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-27T06:27:26+00:00Added an answer on May 27, 2026 at 6:27 am

    GregorianCalendar() Constructs a default GregorianCalendar using the current time in the default time zone with the default locale. Java Doc

    You can do this way.

    while(true) {
           GregorianCalendar gc = new GregorianCalendar();
       l.setText(gc.get(gc.HOUR) + ":" + gc.get(gc.MINUTE) + ":" + gc.get(gc.SECOND));
    }
    

    Now you should understand why you are getting a static clock !

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

Sidebar

Related Questions

The following class is used by another program. When it is accessed, it throws
In the following C program i get the warning: warning #2030: '=' used in
import java.util.*; import java.io.*; import java.util.regex.*; class ZiggyTest2 extends Thread{ String sa; public ZiggyTest2(String
Consider the following code: class Program { static Program() { Program.program1.Value = 5; }
Normally when I am writing the perl program . I used to include following
When I write a Java program I always try to organize my code following
Am trying to run the following python program import re regex=re.compile(http...imgs.xkcd.com.comics.[\\S]*.[jpg|png]) f=open('out.txt') for a
I have the following class hierarchy class Test { public string Name { get;
I've managed to program the following THWorkingMemory class, into a antipattern, the God Object.
Following program is used to sort a list for i in range(len(q)): for j

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.