0

I am using netbeans 6.8 .If a sound file is playing, a button on the jframe wont work while the sound file is playing. The user should still be able to press the button while it is playing. I tried to find it but the codes are very complex. Use Main implements runnable{} Multithread this problem.

RMT
  • 7,040
  • 4
  • 25
  • 37

3 Answers3

5

It sounds like you are playing a sound on the Event despatch thread. Any long running tasks should not be run on this since, as you've seen, it'll lock the gui.

Jim
  • 22,354
  • 6
  • 52
  • 80
2

Try SwingWorker. There are Tutorial and StackOverflow question.

Community
  • 1
  • 1
user802421
  • 7,465
  • 5
  • 40
  • 63
1

You can either implement thread yourself or use higher level tools like

  1. Executors.newSingleThreadExecutor().execute(command)
  2. java.util.Timer: new Timer().schedule(task, 0)
  3. SwingWorker (asm mentioned by @user802421

Here is how you can run task asynchronously using your own thread:

new Thread() {
    public void run() {
        // write here your code
    }
}.start();
AlexR
  • 114,158
  • 16
  • 130
  • 208