//打开文件
public void_jMenuFile_open_actionPerformed(ActionEvent e){
//先创建一个对话框对象,标题设置为“打开媒体文件”
FileDialog fd=new FileDialog(this,"打开媒体文件",FileDialog.LOAD);
//然后设置该对话框的当前目录为上一次打开的目录
fd.setDirectory(currentDirectory);
//调用show函数显示该打开媒体文件对话框
fd.show ();
//如果用户放弃选择文件,则返回
if(fd.getFile()==null)
return;
//设置当前目录为对话框中打开的目录,保存在currentDirectory变量中
currentDirectory=fd.getDirectory();
//如果JMF播放器对象存在,就关闭该播放器对象
if(player!=null)
player.close();
//根据指定的目录和文件名创建一个媒体定位器(MediaLocator)对象,再利用该媒体定位器对象创建一个JMF播放器对象
try{
player =Manager.createPlayer(new MediaLocator(”file:”+fd.getDirectory() +fd.getFile()));
}
//捕获异常情况
catch(java.io.IOException e2){
System.out.println(e2);
return;
}
catch (NoPlayerException e2){
System.out.println(”不能找到播放器.”);
return;
}
//如果创建播放器对象失败
if (player==null){
System.out.println(”无法创建播放器.”);
return;
first=false;
//设置主界面的标题为媒体文件的目录名加上文件名
this.setTitle("播放文件位置"+fd.getDirectory()+fd.getFile());
//将JVideoPlayerFrame对象注册为来自JMF播放器对象的控制器事件的动作监听器
//player.addControllerListener(this);
//最后,让JMF播放器对象预先提取媒体文件的内容
player.prefetch();
}