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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:22:02+00:00 2026-06-17T02:22:02+00:00

Just have a look on this block of code: public Reminder() { a[0]=1000; a[1]=3000;

  • 0

Just have a look on this block of code:

public Reminder() {

    a[0]=1000;
    a[1]=3000;
    a[2]=1000;
   a[3]=5000;
    timer = new Timer();

  timer.schedule(new RemindTask(),0,  a[i]);

  }
 //////////////////////
   class RemindTask extends TimerTask  {

    public void run() {

  point =point +arr[i].length();

     doc.setCharacterAttributes(0,point+1, textpane.getStyle("Red"), true);
     i++;

    }
    }

I want delay to be changed after each task,so the timings are stored in an array.
When i++ is preformed(pointer to array),the timings are not changed;the subsequent rate of delay is same as the first delay value.Why it dosn’t change?

EDIT:

Here’s an SSCCE if required:

import java.awt.Color;
import java.lang.reflect.InvocationTargetException;
import java.util.Timer;
import java.util.TimerTask;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;


public class Reminder {
static   JFrame frame;
Toolkit toolkit;
Timer timer;
int point=0;
static   StyledDocument doc;
 static   JTextPane textpane;
 String[] arr={"Tes"," hiiii"," what"," happpn"};
public int i=0;
long[] a=new long[4];
public Reminder() {

    a[0]=1000;
    a[1]=3000;
    a[2]=1000;
   a[3]=5000;
    timer = new Timer();

  timer.schedule(new RemindTask(),0,  a[i]);

 }

 class RemindTask extends TimerTask  {

    public void run() {

  point =point +arr[i].length();

     doc.setCharacterAttributes(0,point+1, textpane.getStyle("Red"), true);
     i++;


    }
  }
 public static void newcompo()
{

    JPanel panel = new JPanel();
    doc = (StyledDocument) new DefaultStyledDocument();
  textpane = new JTextPane(doc);
    textpane.setText("Test hiiii what happpn");
    javax.swing.text.Style style = textpane.addStyle("Red", null);
    StyleConstants.setForeground(style, Color.RED);
           panel.add(textpane);
    frame.add(panel);
    frame.pack();

 }
  public static void main(String args[]) throws InterruptedException,   InvocationTargetException {
      SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            frame.setVisible(true);

           newcompo();
        }
    });



 Reminder aa=  new Reminder();

  }
 }
  • 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-17T02:22:03+00:00Added an answer on June 17, 2026 at 2:22 am

    When using Swing, better to use javax.swing.Timer over javax.util.Timer. That will give you the setDelay method:

    timer = new Timer(0, new ActionListener() {
    
        @Override
        public void actionPerformed(ActionEvent e) {
            if (i > a.length) { // check when to stop
                timer.stop();
                return;
            }
    
            point = point + arr[i].length();
            doc.setCharacterAttributes(0, point + 1, textpane.getStyle("Red"), true);
            i++;
    
            // Change delay period
            timer.setDelay(a[i]);
        }
    });
    timer.setDelay(a[0]);
    timer.start();
    

    This will required you to change the type of your delay array a, from

    long[] a = new long[4];
    

    to this:

    int[] a = new int[4];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bug in this block of code. The debugger suggest it´s cause
I want to have the look of UITableViewCellStyleValue1 but instead of just only having
I have noticed that the Windows Vista/7 dialogs look MUCH better than just a
I just have this issue with reading from a network stream in C#. Since
This is a code block I use in most of my DNN Settings modules
I have been using the block of code below to supposedly stop sql injections.
Hello and thanks in advance for taking a look at this. I have discovered
This is what I have so far: public class Numbers { // Fields public
For a research project I have a relatively large block of code that is
I currently have this code in the page/div when you load it without anything

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.