views:

54

answers:

1

Im pretty new to programming....so I am making a music Player that needs some features I need to treat one Event at the same time in 2 classes. For example...

The Player is plaing music on its own thread, when this music is done, it fires musicFinished(MusicEvent), go to the Playlist class and asksForAnotherMusicToPlay(), then starts playing again. When musicFinished fires all this happens at the same time: -A Logger, who is listening for the event go write it to a log file. (Do I need another thread here or the event is already treated in another thread?) -The GUI displays that the music finished, updates a label and set clock to 0.(For this I would use SwingUtilities.invokeLater, right??)

So whats the best solution for this case? Making my own event? What about the threads? do I have to make then myself??I already googled for it and found out that the actionPerformed is executed in the EDT(Event Dispatching Thread) but I dont know for other events. are they all??? Thanks

A: 

All Swing event handlers are called from the EDT. Also, SwingUtilities.invokeLater will run your code in the EDT too, it'll just wait until all pending event handlers are called. I'm not sure if this is what you want - if not, you'll need to start your own thread.

Mike Baranczak
so I just need to make my own event, extending java.util.EventObject ?? and when it fires it will be handled on the EDT ? So for updating GUI I can just write GUI code in the event hanlder, and for making other stuff I will start another thread??Thanks
fredcrs
I have made some testes here and realized that the Event I created extending java.util.EventObject when fired, was NOT handled in the EDT. I used SwingUtilities.isEvenItDispatchingThread(), for that.It was handled on my main thread
fredcrs