Last active
August 29, 2015 14:12
-
-
Save akameco/53b5538bcf319d5abd38 to your computer and use it in GitHub Desktop.
mp3再生
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javazoom.jlgui.basicplayer.BasicPlayer; | |
import javazoom.jlgui.basicplayer.BasicPlayerException; | |
import javax.swing.*; | |
import java.awt.*; | |
import java.awt.event.ActionEvent; | |
import java.io.File; | |
public class SamplePlayer extends JPanel { | |
BasicPlayer player; | |
public SamplePlayer() { | |
super(new BorderLayout()); | |
player = new BasicPlayer(); | |
JTextField tf = new JTextField(); | |
add(tf,BorderLayout.NORTH); | |
add(new JButton(new AbstractAction("再生") { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
try { | |
player.open(new File(tf.getText())); | |
player.play(); | |
} catch (BasicPlayerException e1) { | |
e1.printStackTrace(); | |
} | |
} | |
})); | |
} | |
public static void main(String[] args) { | |
JFrame w = new JFrame(); | |
w.add(new SamplePlayer()); | |
w.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); | |
w.setSize(200, 100); | |
w.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment