Results 1 to 2 of 2
  1. #1
    couline is offline Member
    Join Date
    Jan 2012
    Posts
    9
    Rep Power
    0

    Default need help with the Timer in java.

    anyone can teach or show me the code on how to use the timer. i have my code here, i used the Thread.sleep instead of the timer. i want to know how can i insert and use the timer instead of the thread.sleep. thanks in advance, here's my code
    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    
    
    public class DrawingProject extends JFrame
    {
    	public static void main(String[] args)
    	{
    			DrawingProject frame = new DrawingProject();
    			frame.setSize(1050,850);
    			frame.setVisible(true);
    	}
    
    	public void paint(Graphics g)
    	{
    		Random rand = new Random();
    		for(int c = 0; c < 1000; c++)
    		{
    
    			int x = rand.nextInt(850);
    			int y = rand.nextInt(850);
    			int x2 = rand.nextInt(850);
    			int y2= rand.nextInt(850);
    			int x3 = rand.nextInt(850);
    			int y3 = rand.nextInt(850);
    			int w = rand.nextInt(250);
    			int h = rand.nextInt(250);
    			int w2 = rand.nextInt(250);
    			int h2 = rand.nextInt(250);
    			int w3 = rand.nextInt(250);
    			int h3 = rand.nextInt(250);
    			int w4 = rand.nextInt(50);
    			int h4 = rand.nextInt(50);
    			int R = rand.nextInt(256);
    			int G = rand.nextInt(256);
    			int B= rand.nextInt(256);
    			Color r = new Color(R, G, B);
    			Color r2 = new Color(R, B, G);
    			Color r3 = new Color(B, R, G);
    
    			g.setColor(r);
    			g.fillOval(x,y,w,h);
    			g.setColor(r2);
    			g.fillRect(x2,y2,w2,h2);
    			g.setColor(r3);
    			g.fillRoundRect(x3,y3,w3,h3,w4,h4);
    
    			try
    			{
    	      		Thread.sleep(1000);
    	    	}catch(InterruptedException ex){}
    
    		}
    
    	}
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

Similar Threads

  1. Stopping a Timer from Inside the timer
    By krishnan in forum Java Applets
    Replies: 2
    Last Post: 10-04-2010, 11:15 PM
  2. Need Help with timer (Java)
    By acash229 in forum New To Java
    Replies: 58
    Last Post: 09-13-2010, 01:32 PM
  3. New to Java need help with a timer
    By kd0jzi in forum New To Java
    Replies: 3
    Last Post: 03-20-2010, 03:20 AM
  4. Replies: 0
    Last Post: 04-04-2008, 02:46 PM
  5. Help with timer in java
    By barney in forum Advanced Java
    Replies: 1
    Last Post: 08-01-2007, 10:24 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
  •