Java如何实现MP3播放!!做
import t。*;
import t。event。*;
import 。*;
import javax。swing。*;
import dia。*;
public class JMFTest
extends JFrame {
private Player player;
private File file;
public JMFTest() {
super("JMF-代刚祘Α(by Sungo)");
JButton openFile = new JButton("叫匡璶冀郎 (*。 Wav*。MP3*。MIDI。。)");
tFont(new t。Font(...全部
import t。*;
import t。event。*;
import 。*;
import javax。swing。*;
import dia。*;
public class JMFTest
extends JFrame {
private Player player;
private File file;
public JMFTest() {
super("JMF-代刚祘Α(by Sungo)");
JButton openFile = new JButton("叫匡璶冀郎 (*。
Wav*。MP3*。MIDI。。)");
tFont(new t。Font("灿砰", 0, 15));
tForeground(new Color(255, 255, 255));
tBackground(new Color(204, 102, 255));
dActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
openFile();
createPlayer();
}
}
);
getContentPane()。
add(openFile, BorderLayout。SOUTH);
setSize(365, 84);
show();
try {
jbInit();
}
catch (Exception e) {
intStackTrace();
}
}
private void openFile() {
JFileChooser fileChooser = new JFileChooser();
tFileSelectionMode(
JFileChooser。
FILES_ONLY);
int result = owOpenDialog(this);
if (result == JFileChooser。CANCEL_OPTION) {
file = null;
}
else {
file = tSelectedFile();
}
}
private void createPlayer() {
if (file == null) {
return;
}
removePreviousPlayer();
try {
player = eatePlayer( URL());
dControllerListener(new EventHandler());
art();
}
catch (Exception e) {
owMessageDialog(this,
"郎摸岿粇┪琌тぃ赣郎竚",
"岿粇癟矗ボ",
JOptionPane。
ERROR_MESSAGE);
}
}
private void removePreviousPlayer() {
if (player == null) {
return;
}
ose();
Component visual = tVisualComponent();
Component control = tControlPanelComponent();
Container c = getContentPane();
if (visual != null) {
move(visual);
}
if (control != null) {
move(control);
}
}
public static void main(String args[]) {
JMFTest app = new JMFTest();
dWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System。
exit(0);
}
}
);
}
private class EventHandler
implements ControllerListener {
public void controllerUpdate(ControllerEvent e) {
if (e instanceof RealizeCompleteEvent) {
Container c = getContentPane();
Component visualComponent =
tVisualComponent();
if (visualComponent != null) {
d(visualComponent, BorderLayout。
CENTER);
}
Component controlsComponent =
tControlPanelComponent();
if (controlsComponent != null) {
d(controlsComponent, BorderLayout。
NORTH);
}
Layout();
}
}
}
private void jbInit() throws Exception {
tDefaultCloseOperation(HIDE_ON_CLOSE);
tContentPane()。
setBackground(new Color(0, 102, 255));
tResizable(false);
}
}
-------------
繁体字都变成乱码了,本来想传整个文件的,但太大了,IASK居然只能传200K的东西。
收起