|
-
February 17th, 2007, 06:14 AM
#1
JFileChooser & EDT
Hey again,
My project consists of one Applet and an MP3Player class.
I'm using a JFileChooser to play an mp3 song. The problem is that in my
applet I have 2 buttons: start + stop buttons ... I must add an
ActionListener to those buttons, but it is not working with inner classes.
Any other way to make it ?
The start button calls the function "play()" located in the MP3Player class
The stop button calls the function "stop()" located in the MP3Player class
Code:
boolean openFile(){
JFileChooser fc = new JFileChooser ();
fc.setDialogTitle ("Open File");
fc.setFileSelectionMode ( JFileChooser.FILES_ONLY);
fc.setCurrentDirectory (new File ("."));
fc.setFileFilter(fMp3Filter);
int result = fc.showOpenDialog (this);
if (result == JFileChooser.CANCEL_OPTION) {
return true;
}
else
if (result == JFileChooser.APPROVE_OPTION) {
fFile = fc.getSelectedFile ();
nowplaying.setText(fFile.getName());
MP3Player mp3=new MP3Player(fc.getSelectedFile().getAbsolutePath());
start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if(evt.getSource() == start)
mp3.play();
}});
stop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if(evt.getSource() == stop)
mp3.stop();
}});
....
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
Last edited by tima; February 18th, 2007 at 07:05 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|