Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Threading basics problem

 
Greenhorn
Posts: 23
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

Below i've tried to create a basic java audio player- When the user selects an audio file by clicking the button that file begins to play. But then i realized that javazoom's play() method hangs the app while playing the file so i need to put that in a new thread. So i tried to implement Runnable like this: but that gives me the error: . What i need to do here?

 
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kasun Liyanage wrote:What i need to do here?



Runnable is *not* a marker interface -- it has a method. If you declare that something implements Runnable, you will actually have to implement the method of the Runnable interface.

Henry
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Sheriff Wong said, if your JavaMusicPlayerBasic class implements Runnable then it has to have a method called run(), which it does not.

But I don't think you should have your JavaMusicPlayerBasic class implementing Runnable. Correct me if I'm wrong but I don't think you want the whole dialog box running in a separate thread, you just want to play the mp3 in a separate thread so that your dialog box still responds to user input.

I would create a separate class that implements Runnable. Call it, for example, Mp3Player. Then in your jButton_browseActionPerformed() method, instead of creating an instance of Player, you would create an instance of Mp3Player and call its start() method. Calling start() creates a new thread and calls the run() method on that new thread. Move the creation of Player and the play() method from jButton_browseActionPerformed() to the run() method of Mp3Player so that the mp3 file is played on the new thread.
 
Kasun Liyanage
Greenhorn
Posts: 23
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys! Tom, that was the type of explanation i needed, thanks. I'll give feedback after trying that.
 
Kasun Liyanage
Greenhorn
Posts: 23
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's working! Thanks again, Tom.
 
Run away! Run away! Here, take this tiny ad with you:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic