ImageVerifierCode 换一换
格式:DOCX , 页数:13 ,大小:16.62KB ,
资源ID:6003693      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6003693.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(一个简单的音乐播放器的java代码.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

一个简单的音乐播放器的java代码.docx

1、一个简单的音乐播放器的java代码import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.*;import javax.swing.*;import javax.media.bean.playerbean.*;import java.io.IOException;import javax.swing.JOptionPane;import java.awt.*;public class lyt extends JFrame implements Runnable public MediaPlayer

2、soumd1; private JButton playSound, stopsound, tjian,loopSound;private JMenuItem jmiOpen,jmiSave,jmiExit,jmiAbout; public JPanel jp1, jp2, jp3, jp4;public JList jl; private JButton last, next, stop;public Vector vector, mingcheng;boolean fo = false, geshi = false;JLabel jl1, jl2, sj1, sj2;JTextField

3、jt1, jt2;int a = 0, b = 0, you = 1, mm = 0; public lyt() super(200842018java音乐播放器); soumd1 = new MediaPlayer(); Container c = getContentPane(); c.setLayout(new FlowLayout(); mingcheng = new Vector(); jp1 = new JPanel(); c.add(jp1);JMenuBar mb=new JMenuBar(); setJMenuBar(mb);JMenu fileMenu=new JMenu(

4、文件); mb.add(fileMenu); JMenu helpMenu=new JMenu(帮助); mb.add(helpMenu); fileMenu.add(jmiOpen=new JMenuItem(打开); fileMenu.add(jmiSave=new JMenuItem(播放);helpMenu.add(jmiAbout=new JMenuItem(关于); JPanel jp2 = new JPanel(); jp2.setLayout(new FlowLayout(); jp2.add(last = new JButton(后退); jp2.add(playSound

5、= new JButton(播放); jp2.add(tjian = new JButton(添加); jp2.add(next = new JButton(前进); jp2.add(stopsound = new JButton(停止); jp2.add(loopSound= new JButton(循环); getContentPane().add(jp2, BorderLayout.SOUTH); jp2 = new JPanel(); jp2.add(playSound); jp2.add(stopsound); c.add(jp2); jp4 = new JPanel(); sj1

6、= new JLabel(); sj2 = new JLabel(); jp4.add(sj1); jp4.add(sj2); c.add(jp4); vector = new Vector(); jl = new JList(mingcheng); jl.setVisibleRowCount(4); jl.setFixedCellHeight(30); jl.setFixedCellWidth(265);jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); c.add(new JScrollPane(jl); jp3 = new

7、JPanel(); jp3.add(tjian); c.add(jp3); try String s = d:music.txt; ObjectInputStream input = new ObjectInputStream( new FileInputStream(s); lujin a1 = (lujin) input.readObject(); mingcheng = a1.b; vector = a1.a; jl.setListData(mingcheng); catch (Exception e) System.out.println(D盘没有保存音乐文件); jmiOpen.ad

8、dActionListener(new ActionListener() public void actionPerformed(ActionEvent event) JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setCurrentDirectory(new File(.); fileChooser .setFileFilter(newjavax.swing.filechooser.

9、FileFilter() public boolean accept(File file) String name = file.getName().toLowerCase(); return name.endsWith(.mp3) | file.isDirectory(); public String getDescription() return 音乐文件(*.mp3); ); if (fileChooser.showOpenDialog(lyt.this) =JFileChooser.APPROVE_OPTION) String fileName =fileChooser.getSele

10、ctedFile() .getAbsolutePath(); vector.add(fileName); StringBuffer buffer = daoxu(fileName); mingcheng.add(buffer); ); tjian.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChoos

11、er.FILES_AND_DIRECTORIES); fileChooser.setCurrentDirectory(newFile(.); fileChooser .setFileFilter(newjavax.swing.filechooser.FileFilter() public boolean accept(File file) String name =file.getName().toLowerCase(); return name.endsWith(.mp3) | file.isDirectory(); public String getDescription() return

12、 音乐文件(*.mp3); ); if (fileChooser.showOpenDialog(lyt.this) =JFileChooser.APPROVE_OPTION) String fileName =fileChooser.getSelectedFile() .getAbsolutePath(); vector.add(fileName); StringBuffer buffer = daoxu(fileName); mingcheng.add(buffer); ); jmiSave.addActionListener(new ActionListener() public void

13、 actionPerformed(ActionEvent e) if (jl.getSelectedIndex() = 0) String yy = (String)vector.get(jl.getSelectedIndex(); File ff = new File(yy); if (ff.exists() if (yy.matches(Ss*.mp3) |yy.matches(Ss*.mp3) if (soumd1 != null) a = 0; b = 0; you = 0; soumd1.stop(); soumd1.setMediaLocation(file:/ +yy); fo

14、= true; soumd1.start(); geshi = true; try Thread.sleep(500); catch (InterruptedException eee) else JOptionPane.showMessageDialog(null, 无法播放); else JOptionPane.showMessageDialog(null, 此歌曲已经存在); else JOptionPane.showMessageDialog(null, 请选择音乐文件); ); loopSound.addActionListener(new ActionListener() publ

15、ic void actionPerformed(ActionEvent e) if (jl.getSelectedIndex() = 0) String yy = (String) vector.get(jl.getSelectedIndex(); File ff = new File(yy); if (ff.exists() if (yy.matches(Ss*.mp3)| yy.matches(Ss*.MP3) if (soumd1 != null) a = 0; b = 0; you = 0; soumd1.stop(); soumd1.setMediaLocation(file:/ +

16、 yy); fo = true; soumd1.start(); geshi=true; try Thread.sleep(500); catch (InterruptedException we) else JOptionPane.showMessageDialog(null, 不支持此格式,无法播放); else JOptionPane.showMessageDialog(null, 此歌曲文件已经存在); else JOptionPane.showMessageDialog(null, 请选择音乐文件); ); playSound.addActionListener(new Action

17、Listener() public void actionPerformed(ActionEvent e) if (jl.getSelectedIndex() = 0) String yy = (String)vector.get(jl.getSelectedIndex(); File ff = new File(yy); if (ff.exists() if (yy.matches(Ss*.mp3) |yy.matches(Ss*.mp3) if (soumd1 != null) a = 0; b = 0; you = 0; soumd1.stop(); soumd1.setMediaLoc

18、ation(file:/ + yy); fo = true; soumd1.start(); geshi = true; try Thread.sleep(500); catch (InterruptedException eee) else JOptionPane.showMessageDialog(null, 无法播放); else JOptionPane.showMessageDialog(null, 此歌曲已经存在); else JOptionPane.showMessageDialog(null, 请选择音乐文件); ); stopsound.addActionListener(ne

19、w ActionListener() public void actionPerformed(ActionEvent e) a = 0; b = 0; you = 0; mm = 0; geshi = false; fo = false; sj1.setText(null); sj2.setText(null); if (jl.getSelectedIndex() = 0) soumd1.stop(); ); jl.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent event) if (event.g

20、etClickCount() = 2) if (jl.getSelectedIndex() = 0) String yy = (String)vector.get(jl.getSelectedIndex(); File ff = new File(yy); if (ff.exists() if (yy.matches(Ss*.mp3) |yy.matches(Ss*.mp3) if (soumd1 != null) a = 0; b = 0; you = 0; soumd1.stop(); soumd1.setMediaLocation(file:/ + yy); fo = true; sou

21、md1.start(); geshi = true; try Thread.sleep(500); catch (InterruptedException e) else JOptionPane.showMessageDialog(null, 无法播放); else JOptionPane.showMessageDialog(null, 此歌曲已经存在); if (event.isMetaDown() if (jl.getSelectedIndex() = 0) int a = jl.getSelectedIndex();jt1.setText(mingcheng.get(jl.getSele

22、ctedIndex() + );jt2.setText(vector.get(jl.getSelectedIndex() + ); ); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) String s = d:music.txt; mmm(vector, mingcheng, s); System.exit(0); ); setSize(370, 270); setVisible(true); public void run() while (true) Date now = new

23、 Date(); try Thread.sleep(1000); catch (InterruptedException e) if (geshi) you = (int) soumd1.getMediaTime().getSeconds(); mm = you % 60; if (you != 0) if (you % 60 = 0) b+; sj1.setText(b + : + mm); public StringBuffer daoxu(String fileName) String mc = ; for (int i = fileName.length(); i = 1; i-) i

24、f (fileName.charAt(i - 1) = ) break; mc += fileName.charAt(i - 1); StringBuffer buffer = new StringBuffer(mc); StringBuffer mm = buffer.reverse(); return mm; public void mmm(Vector vector, Vector mingcheng,String lujin) lujin a = new lujin(vector, mingcheng); try ObjectOutputStream output = newObjec

25、tOutputStream(new FileOutputStream( lujin); output.writeObject(a); output.flush(); output.close(); catch (Exception e) public static void main(String agrs) lyt s = new lyt(); Thread t1 = new Thread(s); t1.start(); s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); class lujin implements Serializable Vector a = new Vector(); Vector b = new Vector(); public lujin(Vector vector, Vector mingcheng) a = vector; b = mingcheng;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1