已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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.ImageIcon;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.List;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 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 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.getIconHeight();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 * * return 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(), null);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) / 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 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;/* * 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(ActionEvent 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);jchoose.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.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() 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 Rectangle(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 getJButton3() if (jButton3 = null) jButton3 = new JButton();jButton3.setBounds(new Rectangle(380, 247, 89, 29);jButton3.setText(播放);jButton3.addActio
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025私营企业员工试用期合同模板
- 薪起程签合同
- 见证送检合同
- 2025年赣州联考地理试卷及答案
- 2025简化版药品采购招标合同书范本
- 汇通租赁合同(标准版)
- 吊卸安全合同
- 装饰改造合同
- 深圳写字楼租赁合同
- 2025珠宝首饰批发代理合同
- 电池极柱连接行业现状深度解析
- 叮当快药大健康生态圈战略解析
- 腹腔镜下直肠癌护理个案讲课件
- 3.1《祝福》课件-2024-2025学年高教版(2023)中职语文基础模块下册
- 纯化水检测管理制度
- 塔里木油田分公司新疆塔里木盆地吐孜洛克气田开采矿山地质环境保护与土地复垦方案
- 第三章新时代交通文化与精神第二节交通精神具体体现13课件
- 2025年4月自考00312政治学概论试题及答案含评分标准
- DB21-T1642-2024-镁质耐火原料及制品单位产品能源消耗限额-辽宁省
- 2025年陕西蒲城清洁能源化工有限责任公司招聘笔试参考题库附带答案详解
- 酒店前厅部培训
评论
0/150
提交评论