Timed Random number

Posted on 2006-04-03
Last Modified: 2011-09-20
Is there a way to create a random number timed? For example, I know how to create a random number but I need to be able to press a botton and create a random number every say 3-4 seconds.  That is what I am having trouble with, how to create a random number every x seconds.  I would press a button then the random number generator would start and give me a random number every x seconds, this will continue until I press another button at which button the random numbers would stop.
Question by:urivera
    LVL 92

    Expert Comment


    Author Comment

    could you show some examples please, thanks
    LVL 92

    Accepted Solution

    that link has an example :)

    put the code you want to get run in the run() method at

    // Task here ...
    LVL 30

    Expert Comment

    >> but I need to be able to press a botton

    So you want to start at the button-click? Then you need to implement an ActionListener and add it to the button:

    button.addActionListener ( yourActionListener ) ;

    In the actionPerformed () method of the listener, start the timer.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    classnotfoundexception 3 28
    Connect to IP Camera using Java 4 59
    scoresAverage challenge 8 58
    dividesSelf challange 15 57
    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now