java简单播放器源码.doc

上传人:仙人指路1688 文档编号:2386951 上传时间:2023-02-17 格式:DOC 页数:7 大小:27KB
返回 下载 相关 举报
java简单播放器源码.doc_第1页
第1页 / 共7页
java简单播放器源码.doc_第2页
第2页 / 共7页
java简单播放器源码.doc_第3页
第3页 / 共7页
java简单播放器源码.doc_第4页
第4页 / 共7页
java简单播放器源码.doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《java简单播放器源码.doc》由会员分享,可在线阅读,更多相关《java简单播放器源码.doc(7页珍藏版)》请在三一办公上搜索。

1、import java.awt.BorderLayout;import javax.media.Manager;import javax.media.NoPlayerException;import javax.media.Player;import javax.sound.sampled.AudioFormat;import javax.sound.sampled.AudioSystem;import javax.sound.sampled.DataLine;import javax.sound.sampled.SourceDataLine;import javax.swing.ImageI

2、con;import javax.swing.JFileChooser;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JFrame;import javax.swing.JScrollPane;import java.awt.Rectangle;import javax.swing.JTable;import java.awt.Dimension;import javax.swing.JTextPane;import javax.swing.JScrollBar;import java.awt.Li

3、st;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.io.IOException;import .MalformedURLException;import javax.swing.JButton;import javax.swing.filechooser.FileNameExtensionFilter;public class Hello extends JFrame implements ActionListener private

4、 static final long serialVersionUID = 1L;private JPanel jContentPane = null;private List list = null;private JButton jButton = null;private Player play; / jve:decl-index=0:private String str = null;private JButton jButton1 = null;private JButton jButton2 = null;private boolean b=false;private static

5、 SourceDataLine objSDL;private JButton jButton3 = null;/* * This is the default constructor */public Hello() super();ImageIcon backIcon = new ImageIcon(getClass().getResource(/image/hehe.jpg);final JLabel backLabel = new JLabel(backIcon); / 创建背景标签backLabel.setSize(backIcon.getIconWidth(), backIcon.g

6、etIconHeight();backLabel.setLocation(0, 0);this.add(backLabel);initialize();/* * This method initializes this * * return void */private void initialize() this.setSize(594, 346);this.setContentPane(getJContentPane();this.setTitle(达达播放器);setVisible(true);/* * This method initializes jContentPane * * r

7、eturn javax.swing.JPanel */ Start Output/* 打开音频设备.* param intFreq 采样率。* param iBits PCM位深(例如16)。* param channels 声道数*/private JPanel getJContentPane() if (jContentPane = null) jContentPane = new JPanel();jContentPane.setLayout(null);jContentPane.add(getList(), null);jContentPane.add(getJButton(), nu

8、ll);jContentPane.add(getJButton1(), null);jContentPane.add(getJButton2(), null);jContentPane.add(getJButton3(), null);return jContentPane;public void play(String str, List list) File ff = new File(str + list.getSelectedItem();try play = Manager.createPlayer(ff.toURL(); catch (NoPlayerException e1) /

9、 TODO Auto-generated catch blocke1.printStackTrace(); catch (MalformedURLException e1) / TODO Auto-generated catch blocke1.printStackTrace(); catch (IOException e1) / TODO Auto-generated catch blocke1.printStackTrace();play.start();/* * This method initializes list * * return java.awt.List */private

10、 List getList() if (list = null) list = new List();list.setBounds(new Rectangle(67, 16, 425, 206);list.addItemListener(new java.awt.event.ItemListener() public void itemStateChanged(java.awt.event.ItemEvent e) if (play = null) play(str, list);b=true; else play.close();play(str, list););return list;/

11、* * This method initializes jButton * * return javax.swing.JButton */private JButton getJButton() if (jButton = null) jButton = new JButton();jButton.setBounds(new Rectangle(15, 244, 128, 31);jButton.setText(添加歌曲文件夹);jButton.addActionListener(this);return jButton;public void actionPerformed(ActionEv

12、ent e) JFileChooser jchoose = new JFileChooser();jchoose.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);FileNameExtensionFilter filter = new FileNameExtensionFilter(MP3,MP3);jchoose.setMultiSelectionEnabled(true);/ 选择文件夹jchoose.setFileFilter(filter);jchoose.setMultiSelectionEnabled(true);jchoos

13、e.showOpenDialog(this);if (jchoose.getSelectedFile() != null) if (list != null)list.clear();File file = jchoose.getSelectedFile();str = jchoose.getCurrentDirectory()+ jchoose.getSelectedFile().getName() + ;File f = file.listFiles();for (int i = 0; i f.length; i+) if (fi.getName().endsWith(.mp3)list.

14、add(fi.getName();/* * This method initializes jButton1 * * return javax.swing.JButton */private JButton getJButton1() if (jButton1 = null) jButton1 = new JButton();jButton1.setBounds(new Rectangle(155, 246, 115, 30);jButton1.setText(随机播放);jButton1.addActionListener(new java.awt.event.ActionListener(

15、) public void actionPerformed(java.awt.event.ActionEvent e) / Thread Haha=new RadamPlay(list);/ Haha.start(););return jButton1;/* * This method initializes jButton2 * * return javax.swing.JButton */private JButton getJButton2() if (jButton2 = null) jButton2 = new JButton();jButton2.setBounds(new Rec

16、tangle(280, 246, 81, 30);jButton2.setText(暂停);jButton2.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent e) if(play!=null) play.stop(); );return jButton2;/* * This method initializes jButton3 * * return javax.swing.JButton */private JButton

17、getJButton3() if (jButton3 = null) jButton3 = new JButton();jButton3.setBounds(new Rectangle(380, 247, 89, 29);jButton3.setText(播放);jButton3.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent e) if(play!=null)play.start();elseplay(str, list););return jButton3;public static void main(String args)new Hello(); / jve:decl-index=0:visual-constraint=47,10

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号