Results 1 to 5 of 5
  1. #1
    Ragoune is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default Trying to create simple Timer, doesn't work

    Hi,

    I'm trying to make a timer to update my progressbar using this code:
    Java Code:
    JProgressBar progress_song;
    progress_song = new JProgressBar();
    progress_song.setVisible(true);
    frame.add(progress_song);
    try
    {	
    	player = new Player(new FileInputStream("c:\\music\\0.mp3"));
    	player.play();
    	
    	progress_song.setMaximum(music_lengths[0]);
    	Timer timer_songprogress = new Timer();
    	timer_songprogress.scheduleAtFixedRate(new TimerTask() {
    		public void run() {
    			progress_song.setValue(player.getPosition());
    		}
    	}, 0, 100);
    catch (JavaLayerException e)
    {
    	System.out.println("a");
    	e.printStackTrace();
    }
    But it doesn't work. Player is a Player() object (I've started this song in the application, so it has no errors).

    When I test the timer using a System.out.println("Execution"); call, it doesn't display anything.

    How come my timer is not running?

    Regards,

    Ragoune
    Last edited by Ragoune; 07-06-2011 at 10:26 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default

    If you want help, you'll have to provide an SSCCE that demonstrates the problem.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Ragoune is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    I've added a bit more but I think it is more that I do it wrong in general.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Doesn't help. If you can't come up with an SSCCE, you're on your own.

    db

  5. #5
    Ragoune is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    Hi,

    Thanks for the replies, and I have found the problem. The code I gave was in a try loop, and player.play(); made the loop exit. Therefore the code after that statement was never executed.

Similar Threads

  1. Load a file doesn't start a timer
    By warchieflll in forum Advanced Java
    Replies: 13
    Last Post: 02-03-2011, 09:34 PM
  2. Replies: 4
    Last Post: 08-23-2010, 04:19 AM
  3. why this doesn't work?
    By hitesh_public in forum New To Java
    Replies: 5
    Last Post: 08-09-2010, 09:07 AM
  4. How do you create a simple timer?
    By Arnold in forum New To Java
    Replies: 2
    Last Post: 11-01-2009, 05:53 PM
  5. Why doesn't this work?
    By Corder10 in forum New To Java
    Replies: 1
    Last Post: 07-04-2009, 11:33 PM

Posting Permissions

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