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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:07:55+00:00 2026-05-26T21:07:55+00:00

I want to stop Timer at some point and then resume it from the

  • 0

I want to stop Timer at some point and then resume it from the point it was paused at. Methods stop(), start() won’t work.

Is there function for pausing Timer and then resuming it? I guess it doesn’t exist.

Does anyone have an idea how to achieve proper Timer pausing?

  • 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-26T21:07:56+00:00Added an answer on May 26, 2026 at 9:07 pm

    javax.swing.Timer.setDelay(int);

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.util.*;
    import javax.swing.*;
    
    public class DelayedPaint {
    
        private CenterPanel center;
        private JFrame frame;
        private JPanel panel;
    
        public static void main(String args[]) {
            EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    new DelayedPaint().createAndShowGUI();
                }
            });
        }
    
        void createAndShowGUI() {
            frame = new JFrame("Delayed Paint");
            frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            frame.setSize(400, 400);
            panel = new JPanel(new BorderLayout());
            frame.setContentPane(panel);
            NorthPanel north = new NorthPanel();
            panel.add(north, BorderLayout.NORTH);
            center = new CenterPanel();
            panel.add(center, BorderLayout.CENTER);
            frame.setVisible(true);
            north.startTimer();
        }
    
        class NorthPanel extends JPanel {
    
            private JLabel lb;
    
            public NorthPanel() {
                lb = new JLabel("Good morning");
                add(lb);
            }
    
            public void startTimer() {
                ActionListener taskPerformer = new ActionListener() {
    
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        setLayout(new FlowLayout(FlowLayout.LEFT));
                        lb.setText("Left");
    //    timer.stop(); // Not needed if setRepeats(false).
                        center.startTimer();
                    }
                };
                javax.swing.Timer timer = new javax.swing.Timer(2000, taskPerformer);
                timer.setRepeats(false);
                timer.start();
            }
        }
    
        class CenterPanel extends JPanel {
    
            private int icnt;
            private Font boldFont = new Font("Dialog", Font.BOLD, 15);
            private Properties centerProps;
            private javax.swing.Timer timer;
    
            public CenterPanel() {
                centerProps = new Properties();
                centerProps.setProperty("circle", "false");
                centerProps.setProperty("lastString", "0");
            }
    
            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2 = (Graphics2D) g;
                if (Boolean.valueOf(centerProps.getProperty("circle"))) {
                    Dimension dim = frame.getSize();
                    g2.draw(new Arc2D.Double(50, 25, dim.height - 100, dim.width - 100, 0, 360, Arc2D.OPEN));
                }
                int j = Integer.parseInt(centerProps.getProperty("lastString"));
                if (j > 0) {
                    g2.setFont(boldFont);
                    for (int i = 1; i <= j; i++) {
                        g2.drawString("" + (char) (i + 48), i * 10, 50);
                    }
                }
            }
    
            public void startTimer() {
                ActionListener taskPerformer = new ActionListener() {
    
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        repaint(); // in paintComponent(...) icnt is already icnt+1.
                        icnt++;
                        if (icnt == 1) {
                            centerProps.setProperty("circle", "true");
                            timer.setDelay(500);
                        } else if (icnt <= 10) {
                            centerProps.setProperty("lastString", String.valueOf(icnt - 1));
                            if (icnt == 10) {
                                timer.stop();
                            }
                        }
                    }
                };
                timer = new javax.swing.Timer(2000, taskPerformer);
                timer.start();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to stop polling server in SignalR? I want to stop
I'm refactoring some time consuming function so that it can be called from a
I have some framework / AOP code that logs exceptions from methods called deeper
I want a timer class that can post messages to a delegate when there
I have a page where when some operation goes wrong i want to start
I want to stop click on any links until the page is loaded. Can
I want to stop outgoing call and open the application. The app is able
for example, if I want to stop lan connection 1 in my control pannel,
I parse a big xml document with Sax, I want to stop parsing the
I have one image animation started using GameQuery. Now I want to stop the

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.