音樂播放器Java課程設(shè)計(jì)報(bào)告_第1頁
音樂播放器Java課程設(shè)計(jì)報(bào)告_第2頁
音樂播放器Java課程設(shè)計(jì)報(bào)告_第3頁
音樂播放器Java課程設(shè)計(jì)報(bào)告_第4頁
音樂播放器Java課程設(shè)計(jì)報(bào)告_第5頁
免費(fèi)預(yù)覽已結(jié)束,剩余11頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、M林電牙科被大喙GUILIN UNIVERSITY OF ELECTRONIC TECHNOLOGYJAVA程序設(shè)計(jì)課程設(shè)計(jì)報(bào)告題目:音樂播放器學(xué)院:計(jì)算機(jī)科學(xué)與工程學(xué)院專業(yè):信息管理與信息系統(tǒng)學(xué)生姓名:楊柏昌學(xué)號(hào):1400320228指導(dǎo)老師:汪華登1. 概要設(shè)計(jì) 2. 詳細(xì)設(shè)計(jì) 3. 測(cè)試 4. 總結(jié) 概要設(shè)計(jì)播放器主要使用JMF框架實(shí)現(xiàn),播放器界面如下正在懵曲r未遺取強(qiáng)曲O咂席睛曲 O單曲循環(huán) 隨機(jī)睡湎I上一首I.就I暫停I停止I 一首款曲列*選擇文件夾 退出詳細(xì)設(shè)計(jì)package design.curriculum.JAVA;import java.awt.*;import java.

2、awt.event.*;import javax.swing.*;import javax.swing.border.Border;import java.io.*;import javax.media.*;public class JMFPlayer extends JFrame implementsActionListener,ControllerListenerPlayer player =null ; / 聲明一個(gè) Player 對(duì)象StringfilePath; /存放音樂文件夾所在目錄StringfileName ; /存放歌曲名稱boolean click =false ; /用

3、來標(biāo)記歌曲是否被點(diǎn)擊int songIndex ; /歌曲元素在列表中的位置int loop =3; /作為播放模式的標(biāo)記JLabel songNameLable ;JRadioButtonsequenceBtn;JRadioButtonsingleBtn ;JRadioButtonrandomBtn ;ButtonGroup loopGroup ;JButton beforeBtn ;JButtonnextBtn;JButtonplayBtn;JButton pauseBtn ;JButtonstopBtn;JButtonfileBtn;JButtonexitBtn;Component co

4、ntrolComponent ; /player 的控制面板Container container ;JPanel songNamejp ;JPanel loopjp ;JPanel btnjp ;JPanel listjp ;JPanel btn2jp ;List list ;public JMFPlayer()super ("音樂播放器");setBounds(480,50,400,600);setResizable( false ); /設(shè)置界面不可修改setVisible( true );container =getContentPane(); / 獲得容器主面板c

5、ontainer .setLayout( new BoxLayout( container ,BoxLayout. Y_AXIS ); songNamejp =new JPanel( new GridLayout(2,2);songNamejp .setSize(400,50);container .add( songNamejp );songNameLable =new JLabel( " 正在播放:未選取歌曲 " );songNamejp .add( songNameLable );songNamejp .setBorder(BorderFactory.createEt

6、chedBorder ();loopjp =new JPanel();loopjp .setSize(400,50);container .add( loopjp );sequenceBtn =new JRadioButton( " 順序播放 " );sequenceBtn .addActionListener(new ActionListener() public void actionPerformed(ActionEventevt )loop = 1;);singleBtn =new JRadioButton( " 單曲循環(huán) " );singleB

7、tn .addActionListener(new ActionListener() public void actionPerformed(ActionEventevt )loop = 0; );randomBtn =new JRadioButton( " 隨機(jī)播放 " );randomBtn .addActionListener(new ActionListener() public void actionPerformed(ActionEventevt )loop = 2;);loopGroup =new ButtonGroup();loopGroup .add( s

8、equenceBtn );loopGroup .add( singleBtn );loopGroup .add( randomBtn );loopjp .add( sequenceBtn );loopjp .add( singleBtn );loopjp .add( randomBtn );btnjp =new JPanel();btnjp .setLayout( new BoxLayout( btnjp ,BoxLayout. X_AXIS );btnjp .setSize(400,50);container .add( btnjp );beforeBtn =new JButton( &qu

9、ot; 上一首 " );playBtn =new JButton(" 播放 " );pauseBtn =new JButton( " 暫停 " );stopBtn =new JButton(" 停止 " );nextBtn =new JButton( " 下一首 " );beforeBtn .addActionListener( this );playBtn.addActionListener(this);pauseBtn .addActionListener( this );stopBtn.addAct

10、ionListener(this);nextBtn.addActionListener(this);btnjp .add( beforeBtn );btnjp .add( playBtn );btnjp .add( pauseBtn );btnjp .add( stopBtn );btnjp .add( nextBtn );listjp =new JPanel( new BorderLayout();listjp .setSize(300,300);container .add( listjp );Border border = BorderFactory. createEtchedBorde

11、r ();Border titled = BorderFactory. createTitledBorder ( border , " 歌曲列表 " );listjp .setBorder( titled );fileBtn=new JButton(" 選擇文件夾" );exitBtn=new JButton(" 退出" );fileBtn.addActionListener(this );exitBtn.addActionListener(this );btn2jp =new JPanel();btnjp .setSize(300,

12、50);container .add( btn2jp );btn2jp .add( fileBtn);btn2jp .add( exitBtn);list =new List();list.setBackground(Color.pink );JScrollPanesongListScroll = new JScrollPane( list );listjp .add( songListScroll, BorderLayout.CENTER);list .addMouseListener( new MouseAdapter() / 對(duì)歌曲點(diǎn)擊的監(jiān)聽public void mouseClicke

13、d(MouseEvent e) if ( e.getClickCount() = 1) fileName = list .getSelectedItem(); songIndex =list .getSelectedIndex(); click =true ; );addWindowListener (new WindowAdapter()public void windowClosing(WindowEvent e)if ( player != null ) player .stop(); player .deallocate();System.exit (0); );validate();

14、/* 對(duì)按鈕事件的處理*/public void actionPerformed(ActionEvente)if ( e.getSource()= fileBtn )FileDialogdialog=new FileDialog(this, " 音樂 " ,FileDialogdialog .setVisible(true );filePath = dialog.getDirectory();if ( filePath != null ) LOAD);File filedir = new File( filePath );File filelist = filedir .l

15、istFiles(); for (File file : filelist ) String filename = file .getName().toLowerCase(); if( filename .endsWith( ".wav" )| filename .endsWith( ".mp3" ) list .add( filename );if ( e.getSource()= playBtn ) if ( click )click =! click ;tryif ( player != null ) player .stop();player .

16、deallocate();if ( controlComponent != null )songNamejp .remove( controlComponent ); songNamejp .validate();player =Manager. createPlayer( newMediaLocator("file:"+filePath +fileName);player.getDuration();player.prefetch();player.addControllerListener(thissongNameLable .setText( fileName );c

17、atch (IOExceptione3) catch (NoPlayerExceptione2) else if (! click ) player .start();if ( e.getSource()= exitBtn ) System. exit (0);if ( e.getSource()= pauseBtn ) if ( player != null )player .stop();if ( e.getSource()= stopBtn ) if ( player != null )player .stop();player .setMediaTime( new Time(0);el

18、se return ;if ( e.getSource()= beforeBtn )int n =list .getItemCount();if ( songIndex <n)songIndex =songIndex -1;if ( songIndex <0)songIndex =n-1;fileName =list .getItem( songIndex );run();if ( e.getSource()= nextBtn )int n =list .getItemCount();if ( songIndex <n)songIndex =songIndex +1;if (

19、 songIndex >=n) songIndex =0;fileName =list .getItem( songIndex );run();public void run() tryif ( player != null ) player .stop(); player .deallocate();if ( controlComponent != null ) songNamejp .remove( controlComponent ); songNamejp .validate();player =Manager. createPlayer ( newMediaLocator( &

20、quot;file:" +filePath +fileName );player .getDuration();player .prefetch();player .addControllerListener(this );songNameLable .setText( fileName );catch (IOException e3 ) catch (NoPlayerException e2) /* * 對(duì)控制面板事件的處理* */ public synchronized void controllerUpdate(ControllerEventevent )if ( event

21、instanceof RealizeCompleteEvent) if ( controlComponent =player .getControlPanelComponent()!=null )songNamejp .add( controlComponent );else if ( event instanceof PrefetchCompleteEvent) player .start();else if ( event instanceof EndOfMediaEvent)player .setMediaTime( new Time(0);if ( loop =0)player .start();if ( loop =1)int n=list .getItemCount();if ( songIndex <n)fileName =list .getItem( songIndex +1);songIndex =songIndex +1;run();if ( loop =2)int n=list .getItemCount();if ( songIndex <n)songInde

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論