还剩8页未读,继续阅读
本资源只提供10页预览,全部文档请下载后查看!喜欢就下载吧,查找使用更方便
文本内容:
import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.*;import javax.swing.*;import javax.media.bean.playerbean.*;import javaJo.lOException;import javax.swing.JOptionPane;import java.awt.*;public classlyt extendsJFrame implementsRunnable{public MediaPlayersoumdl;private JButtonplaySound,stopsound,tjian,loopSound;private JMenultemjmiOpenjmiSavejmiExitjmiAbout;public JPanel jpl,jp2,jp3,jp4;public JListjl;private JButtonlast,next,stop;public Vectorvector,mingcheng;boolean fo=false,geshi=false;JLabel jll,jl2,sjl,sj2;JTextField jtl,jt2;int a=0,b=0,you=1,mm=0;public lyt{super200842018java音乐播放器soumdl=new MediaPlayer;Container c=getContentPane;c.setLayoutfnew FlowLayout;mingcheng=new Vector;jpl=new JPanel;c.addjpl;JMenuBar mb=new JMenuBarf;setJMenuBarmb;JMenu fileMenu=new JMenu文件”;mb.addfileMenu;JMenu helpMenu=new JMenu帮助”;mb.addhelpMenu;fileMenu.addjmiOpen=new JMenultem打开;fileMenu.addjmiSave=new JMenultem“播放;helpMenu.addjmiAbout=new」1\/16门11收171“关于;JPaneljp2=new JPanel;}public staticvoid mainStringagrs[]{lyt s=new lyt;Thread tl=new Threads;tl.start;s.setDefaultCloseOperationJFrame.EXIT_ON_CLOSE;}class lujinimplementsSerializable{Vector a=new Vector;Vector b=new Vector;public lujinVectorvector,Vector mingcheng{a=vector;b=mingcheng;}}jp
2.setLayoutnew FlowLayout;jp
2.addlast=new JButton“后退”;jp
2.addplaySound=new JButton播放;jp
2.addtjian=new JButton“添加;jp
2.addnext=new JButton前进”;jp
2.addstopsound=new JButton“停止;jp
2.addloopSound=new JButton“循环;getContentPane.addjp2,BorderLayout.SOUTH;jp2=new JPanel;jp
2.addplaySound;jp
2.addstopsound;c.addjp2;jp4=new JPanel;sjl=new JLabel;sj2=new JLabel;jp
4.addsjl;jp
4.addsj2;c.addjp4;vector=new Vector;jl=new JListmingcheng;jl.setVisibleRowCount4;jLsetFixedCellHeight30;jl.setFixedCellWidth265;■jl.setSelectionModeListSelectionModel.SINGLE_SELECTION/c.addnew JScrollPanejl;jp3=new JPanel;jp
3.addtjian;c.addjp3;tryString s=d:\\music.txt;Objectinputstream input=newObjectlnputStream newFilelnputStreams;lujin al=lujin input.readObject;mingcheng=al.b;vector=al.a;jl.setListDatamingcheng;catch Exceptione{System.out.printlnD盘没有保存音乐文件”;}jmiOpen.addActionListenernew ActionListener{public voidactionPerformedActionEvent event{JFileChooser fileChooser=new JFileChooser;fileChooser.setFileSelectionModeJFileChooser.FILES_AND_DIRECTORIES;fileChooser.setCurrentDirectorynew File.;fileChooser.setFileFilternewjavax.swing.filechooser.FileFilter{public booleanacceptFile file{String name=file.getName.toLowerCase;return name.endsWith.mp311file.isDirectory;}public StringgetDescription{return”音乐文件*.mp3”;};}if fileChooser.showOpenDialoglyt.this==JFileChooser.APPROVE_OPTION{String fileName=fileChooser.getSelectedFile.getAbsolutePathf;vector.addfileName;StringBuffer buffer=daoxufileName;mingcheng.addbuffer;;}tjian.addActionListenerfnew ActionListener{public voidactionPerformedActionEvent event{JFileChooser fileChooser=new JFileChooser;fileChooser.setFileSelectionModeJFileChooser.FILES_AND_DIRECTORIES;fileChooser.setCurrentDirectorynewFile.;fileChooser.setFileFilternewjavax.swing.filechooser.FileFilter{public booleanacceptFile file{String name=file.getName.toLowerCase;return name.endsWith.mp3||file.isDirectoryO;public StringgetDescription{return”音乐文件*.mp31,;};}if fileChooser.showOpenDialoglyt.this==JFileChooser.APPROVE_OPTION{String fileName=fileChooser.getSelectedFile.getAbsolutePath;vector.addfileName;StringBuffer buffer=daoxufileName;mingcheng.addbuffer;;}jmiSave.addActionListenernew ActionListener{public voidactionPerformedActionEvent e{if jl.getSelectedlndex=0{String yy=String vector.getjl.getSelectedlndex;File ff=new Fileyy;if ff.exists{if yy.matches[\\S\\s]*.mp3||yy.matches,[\\S\\s]*.mp3{if soumdl!=null{a=0;b=0;you=0;soumdl.stop;soumdl.setMediaLocationfile:/+yy;fo=true;soumdl.start;geshi=true;tryThread.sleep500;catch InterruptedExceptioneee{elseJOptionPane.showMessageDialognull,“无法播放”;}elseJOptionPane.showMessageDialognull,“此歌曲已经存在;elseJOptionPane.showMessageDialognull,“请选择音乐文件;}};loopSound.addActionListenernew ActionListener{public voidactionPerformedActionEvent e{if jl.getSelectedlndex=0{String yy=String vector.getjl.getSelectedlndex;File ff=new Fileyy;if ff.exists{if yy.matches[\\S\\s]*.mp3||yy.matches”[\\S\\s]*.MP3{if soumdl!=null{a=0;b=0;you=0;soumdl.stop;soumdl.setMediaLocationHfile:/+yy;fo=true;soumdl.start;geshi=true;try Thread.sleep500;}catch InterruptedExceptionwe{}elseJOptionPane.showMessageDialognull,“不支持此格式,无法播放}elseJOptionPane.showMessageDialognull,“此歌曲文件已经存在elseJOptionPane.showMessageDialognull,“请选择音乐文件;};playSound.addActionListenernew ActionListener{public voidactionPerformedActionEvent e{if jl.getSelectedlndex=0{String yy=Stringvector.getjl.getSelectedlndex;File ff=new Fileyy;if ff.exists{if yy.matches,[\\S\\s]*.mp3,111yy.matches[\\S\\s]*.mp3{if soumdl!=null{a=0;b=0;you=0;soumdl.stop;soumdl.setMediaLocationfile:/+yy;fo=true;soumdl.start;geshi=true;tryThread.sleep500;catch InterruptedExceptioneee{elseJOptionPane.showMessageDialognull,“无法播放”;elseJOptionPane.showMessageDialognull,“此歌曲已经存在elseJOptionPane.showMessageDialognull请选择音乐文件”;;}stopsound.addActionListenernew ActionListenerf{public voidactionPerformedActionEvent e{a=0;b=0;you=0;mm=0;geshi=false;fo=false;sjl.setTextnull;sj
2.setTextnull;if jl.getSelectedlndex=0soumdl.stopO;;}jl.addMouseListenernew MouseAdapter{public voidmousePressedMouseEvent event{if event.getClickCount==2{if jl.getSelectedlndex=0{String yy=Stringvector.getjl.getSelectedlndex;File ff=new Fileyy;if ff.exists{if yy.matches,[\\S\\s]*.mp3,,||yy.matches,[\\S\\s]*.mp3{if soumdl!=null{a=0;b=0;you=0;soumdl.stop;soumdl.setMediaLocationfile:/+yy;fo=true;soumdl.start;geshi=true;try{Thread.sleep500;catch InterruptedExceptione{elseJOptionPane.showMessageDialognull,”无法播放”;elseJOptionPane.showMessageDialognull,”此歌曲已经存在;if event.isMetaDown{if jl.getSelectedlndex=0{inta=jl.getSelectedlndex;jtl.setTextmingcheng.getjl.getSelectedlndex+jt
2.setTextvector.getjl.getSelectedlndex+};addWindowListenernew WindowAdapter{public voidwindowClosingWindowEvente{String s=d:\\music.txtn;mmmvector,mingcheng,s;System.exitO;};setSize370,270;setVisibletrue;}public voidrun{while true{Date now=new Date;tryThread.sleeplOOO;catch InterruptedExceptione{if geshi{you=int soumdl.getMediaTime.getSeconds;mm=you%60;if you!=0if you%60==0{;b++sjl.setTextb++mm;}}public StringBufferdaoxuString fileName{String me=,H,;for inti=fileName.Iength;i=1;i--{if fileName.charAti-1==\\break;me+=fileName.charAti-1;StringBuffer buffer=new StringBuffermc;StringBuffer mm=buffer.reverse;return mm;}public voidmmmVector vector,Vector mingcheng,String lujin{lujin a=new lujinvector,mingcheng;tryObjectOutputStream output=new ObjectOutputStreamnewFileOutputStreamlujin;output.writeObjecta;output.flush;output.close;}catch Exceptione{。
个人认证
优秀文档
获得点赞 0