Re: JFileChooser & ActionListener
Quote:
Error given : "MediaPlayer.java": Error #: 480 : local variable mp3 is accessed from within inner class; needs to be declared final at line 95, column 4
The problem is that the variable mp3 is a local variable and so is only in existence whilst the method by being executed. Your inner classes can be run at any time so they can't reference the mp3 variable as it may not exist when the inner class is executed. One way to solve this problem is by doing as the error message suggests - add the final modifier to the variable declaration: eg
Code:
final MP3Player mp3=new MP3Player(fc.getSelectedFile().getAbsolutePath());
Re: JFileChooser & ActionListener
Yea I got it ! Thx for ur explanation keang .. It worked well
Most appreciated :)
Re: JFileChooser & ActionListener
How am I supposed to use the Thread Event Dispatch Event to call
from an Applet the function play() located in the MP3Player class ?
It is giving me hard times to do it especially that I'm getting the songs from a JFileChooser ....
Code:
boolean openFile(){
[ ... ]
// JFileChooser - open file
if (result == JFileChooser.APPROVE_OPTION) {
fFile = fc.getSelectedFile ();
nowplaying.setText(fFile.getName());
final String c=fc.getSelectedFile().getAbsolutePath();
// .. Thread EDT ..
Runnable code = new Runnable() {
final MP3Player mp3=new MP3Player(c);
public void run() {
mp3.play();
}
};
if (SwingUtilities.isEventDispatchThread()) {
code.run();
} else {
SwingUtilities.invokeLater(code);
}
Thx in advance for ur appreciated help
Re: JFileChooser & ActionListener
Quote:
How am I supposed to use the Thread Event Dispatch Event to call
from an Applet the function play() located in the MP3Player class ?It is giving me hard times to do it especially that I'm getting the songs from a JFileChooser
Firstly are you really sure you want to use the Event Dispatch Thread to do this and secondly unless you are specific about what the problem is how do you expect us to offer you to right advice.
With regard to the event dispatch thread, if you use it to create and play the MP3Player your GUI will effectively lock up until play completes, unless of course the MP3Player creates its own background thread to play the song.