Results 1 to 2 of 2
  1. #1
    subash22 is offline Member
    Join Date
    May 2011
    Posts
    1
    Rep Power
    0

    Default Random Numbers using threads

    I have a program to create random number on an applet.But my idea is to create a new random number for every second on the applet using threads.

    i have the below code to create a single random number

    Java Code:
    import java.awt.*;
    import java.applet.*;
    import java.util.Random;
    public class Ran extends Applet {
        
            public void init() {}
    	int x;
          	public void RandomIntNumber() {
    	Random r = new Random();
    	x=r.nextInt(100);
    	}
            public void paint(Graphics g) {
            g.drawString(Integer.toString(x),50,50);
            }        
              
     }

    Any help will be much appreciated.................plzzz
    Last edited by Fubarable; 06-05-2011 at 03:10 PM. Reason: quote tags changed to code tags

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I would suggest that instead of doing that, use Swing (a JApplet) and a Swing Timer. You can find out more about these in the Oracle Java tutorials.

    Note that the original post was edited and quote tags were changed to code tags to aid readability of the posted code.
    Last edited by Fubarable; 06-05-2011 at 03:11 PM.

Similar Threads

  1. Random numbers
    By zel2zel in forum AWT / Swing
    Replies: 3
    Last Post: 03-09-2011, 06:39 PM
  2. Replies: 8
    Last Post: 04-19-2009, 05:50 PM
  3. Help with random numbers
    By checkmylongboarding in forum New To Java
    Replies: 2
    Last Post: 01-12-2009, 05:47 AM
  4. random numbers without random class`
    By carlos123 in forum New To Java
    Replies: 4
    Last Post: 01-17-2008, 10:44 PM
  5. random numbers
    By carlos123 in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 02:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •