//程序所用到的各种程序包
import java.awt.BorderLayout;
import java.awt.CheckboxMenuItem;
import java.awt.Color;
import http://www.doczj.com/doc/db45f5a4f524ccbff1218465.htmlponent;
import java.awt.Container;
import java.awt.FileDialog;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.ControllerClosedEvent;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.EndOfMediaEvent;
import javax.media.GainControl;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.PrefetchCompleteEvent;
import javax.media.RealizeCompleteEvent;
import javax.media.Time;
import javax.swing.JFrame;
//本程序对应的类;
class MediaPlayer
extends JFrame
implements ActionListener, ControllerListener, ItemListener {
//MediaPlayer类的变量成员的声明;
//JMF提供的播放器对象;
Player player;
Component vc, cc, gcc;
GainControl gc;
//first值用来控制在刚开始程序时显示一幅欢迎界面;loop用以标记是否循环播放;
boolean first = true, loop = false;
//设立一个字符串记录当前打开文件的路径
String currentDirectory;
MediaPlayer(String title) {
super(title);
// 利用一个adapter实现对用户点击窗口系统菜单的关闭按钮
// 时的响应;
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
//调用dispose以执行windowClosed
dispose();
}
public void windowClosed(WindowEvent e) {
if (player != null)
player.close();
System.exit(0);
}
});
//调用设置程序菜单栏的方法成员完成菜单的布置
setupMenu();
setSize(400, 400);
setVisible(true);
}
//本方法用以设置程序菜单栏
public void setupMenu() {
//设置一个菜单
Menu f = new Menu(“文件”);
//往设置的菜单种添加菜单项
MenuItem mi = new MenuItem(“打开”);
mi.addActionListener(this);
f.add(mi);
f.addSeparator();
CheckboxMenuItem cbmi = new CheckboxMenuItem(“循环”, false);
cbmi.addItemListener(this);
f.add(cbmi);
f.addSeparator();
mi = new MenuItem(“退出”);
mi.addActionListener(this);
f.add(mi);
Menu l = new Menu(“播放列表”);
Menu c = new Menu(“播放控制”);
MenuItem move = new MenuItem(“播放”);
move.addActionListener(this);
c.add(move);
c.addSeparator();
MenuItem pause = new MenuItem(“暂停”);
pause.addActionListener(this);
c.add(pause);
c.addSeparator();
MenuItem stop = new MenuItem(“停止”);
stop.addActionL