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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:20:42+00:00 2026-05-31T06:20:42+00:00

I am trying to run a small example which i found from here http://docs.oracle.com/javase/7/docs/api/javax/swing/Timer.html

  • 0

I am trying to run a small example which i found from here http://docs.oracle.com/javase/7/docs/api/javax/swing/Timer.html . However, I get Type mismatch: cannot convert from void to Timer on the timer = new Timer….. line. I was hoping someone could help me.

  int delay = 1000; //milliseconds
  ActionListener taskPerformer = new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
          //...Perform a task...
      }
  };
  new Timer(delay, taskPerformer).start();

Thank you

my code;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.Timer;


public class MyTimerTest 
{
    private JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    Timer timer;
    int delay = 1000; //a second

    public MyTimerTest()
    {
    }


    public void runTimer()
    {
        ActionListener taskPerformer = new ActionListener() 
        {
            @Override
            public void actionPerformed(ActionEvent arg0) {

            }     
        };

        timer = new Timer(delay, taskPerformer).start();
    }
    /**
     * @param args
     */
    public static void main(String[] args) 
    {

    }

}
  • 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-31T06:20:44+00:00Added an answer on May 31, 2026 at 6:20 am

    Your code does not contain line timer = ....
    I believe you tried to write:

    Timer timer = new Timer(delay, taskPerformer).start();

    This cannot be compiled because method start() is void.

    Just separate this line into 2:

    Timer timer = new Timer(delay, taskPerformer);
    timer.start();
    

    EDIT, oh, my assumption is correct. I just have not seen the second line where you are using timer in the second fragment of your code.

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

Sidebar

Related Questions

I am trying run a program from a qmake .pro file which modifies the
Situation: I'm trying run an https store (xcart) under one domain secure.example.com and I
I'm trying to run Junit test from my ant build.xml file. I read here
I'm trying to create a small flash-app, which needs to run as big as
I was developing a small function when trying to run an enumerator across a
I'm trying to run a batch file, as another user, from my web app.
I have a bash file, which I’m trying to run in Cygwin on a
I'm trying to run the following program, which calculates roots of polynomials of degree
I have a small ruby app in which I'm trying to query some information
I am implementing a small queue to handle which process gets to run first.

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.