最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

一個簡單的Java音樂播放器

 更新時間:2017年06月05日 11:49:12   作者:PettyKoKo  
這篇文章主要為大家分享一個簡單的Java音樂播放器,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Java音樂播放器展示的具體代碼,供大家參考,具體內(nèi)容如下

package KKMusic;

 import java.applet.Applet;
 import java.applet.AudioClip;
 import java.awt.BorderLayout;
 import java.awt.EventQueue;
 

 import javax.swing.JFrame;
 import javax.swing.JPanel;
 import javax.swing.border.EmptyBorder;
 import java.awt.CardLayout;
 import javax.swing.JButton;
 import javax.swing.JFileChooser;
 import javax.sound.sampled.FloatControl;
 import javax.sound.sampled.SourceDataLine;
 import javax.swing.GroupLayout;
 import javax.swing.GroupLayout.Alignment;
 import java.awt.event.ActionListener;
 import java.awt.event.ActionEvent;
 import javax.swing.LayoutStyle.ComponentPlacement;
 import javax.swing.JMenuBar;
 import javax.swing.JMenuItem;
 import java.awt.event.ItemListener;
 import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.awt.event.ItemEvent;
 import javax.swing.JMenu;
 import javax.swing.JTextField;
 import javax.swing.SwingConstants;
 import javax.swing.JSlider;
 import java.awt.event.MouseMotionAdapter;
 import java.awt.event.MouseEvent;
 

public class Mp3 extends JFrame {
 
private JPanel contentPane;
 File file;//聲明文件對象
 String filename;
 JFileChooser chooser=new JFileChooser();//創(chuàng)建一個文件選擇器
 private JTextField xiaoxi;
 boolean loop=false;
 AudioClip adc;//聲音音頻剪輯對象
 SourceDataLine line;
 private FloatControl volume = null;
 /**
 * Launch the application.
 */
 public static void main(String[] args) {
 EventQueue.invokeLater(new Runnable() {
 public void run() {
 try {
 Mp3 frame = new Mp3();
 frame.setVisible(true);
 } catch (Exception e) {
 e.printStackTrace();
 }
 }
 });
 }
 

/**
 * Create the frame.
 */
 public Mp3() {
 setTitle("\u97F3\u4E50\u64AD\u653E\u5668");
 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 setBounds(100, 100, 265, 333);
 
JMenuBar menuBar = new JMenuBar();
 setJMenuBar(menuBar);
 
JMenu mnNewMenu = new JMenu("\u6587\u4EF6");
 menuBar.add(mnNewMenu);
 xiaoxi = new JTextField();
 xiaoxi.setColumns(10);
 xiaoxi.setText("歡迎使用本播放器");
 JMenuItem dakai = new JMenuItem("\u6253\u5F00");
 dakai.addActionListener(new ActionListener() {
 public void actionPerformed(ActionEvent e) {
 int value=chooser.showOpenDialog(chooser);//接受文件選擇器的狀態(tài)
 if(value==chooser.APPROVE_OPTION){
 file=chooser.getSelectedFile();//返回選中文件
 filename=file.getName();
 String flag=filename;
 xiaoxi.setText(flag);
 try {
 if(adc!=null)
 adc.stop();
 URL url=new URL("file:"+file.getPath());//創(chuàng)建資源定位
 adc=Applet.newAudioClip(url);
 //adc.play();
 
} catch (MalformedURLException e1) {
 // TODO Auto-generated catch block
 e1.printStackTrace();
 System.out.println("不能播放!");
 }
 }
 }
 });
 mnNewMenu.add(dakai);
 
JMenuItem tuichu = new JMenuItem("\u9000\u51FA");
 tuichu.addActionListener(new ActionListener() {
 public void actionPerformed(ActionEvent e) {

 dispose();
 if(adc!=null)
 adc.stop();
 return ;
 }
 });
 
mnNewMenu.add(tuichu);
 contentPane = new JPanel();
 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
 setContentPane(contentPane);
 
JButton playbtn = new JButton("\u64AD\u653E");
 playbtn.setHorizontalAlignment(SwingConstants.LEFT);
 playbtn.addActionListener(new ActionListener() {
 public void actionPerformed(ActionEvent e) {
 
 String flag="正在播放:"+filename;
 if(adc==null){
 flag="請選擇播放的音樂";
 xiaoxi.setText(flag);
 return;
 }
 adc.play();
 xiaoxi.setText(flag);
 }
 });
 
JButton stopbtn = new JButton("\u6682\u505C");
 stopbtn.setHorizontalAlignment(SwingConstants.LEFT);
 stopbtn.addActionListener(new ActionListener() {
 public void actionPerformed(ActionEvent e) {
 adc.stop();
 String flag="停止播放音樂:"+filename;
 xiaoxi.setText(flag);
 }
 });
 
JButton againbtn = new JButton("\u5FAA\u73AF");
 againbtn.setHorizontalAlignment(SwingConstants.LEFT);
 againbtn.addActionListener(new ActionListener() {
 public void actionPerformed(ActionEvent e) {
 loop =!loop;
 String flag="";
 ; if(loop){
 adc.play();
 adc.loop();//循環(huán)播放
 flag="循環(huán)播放:"+filename;
 }
  else{
  adc.play();
  flag="順序播放"+filename;
  }
  xiaoxi.setText(flag);
 }
 });
 



GroupLayout gl_contentPane = new GroupLayout(contentPane);
 gl_contentPane.setHorizontalGroup(
 gl_contentPane.createParallelGroup(Alignment.LEADING)
 .addGroup(gl_contentPane.createSequentialGroup()
 .addContainerGap()
 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
 .addComponent(xiaoxi, Alignment.LEADING)
 .addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
 .addComponent(playbtn, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(ComponentPlacement.UNRELATED)
 .addComponent(stopbtn, GroupLayout.PREFERRED_SIZE, 66, GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(ComponentPlacement.UNRELATED)
 .addComponent(againbtn, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE)))
 .addContainerGap(15, Short.MAX_VALUE))
 );
 gl_contentPane.setVerticalGroup(
 gl_contentPane.createParallelGroup(Alignment.TRAILING)
 .addGroup(gl_contentPane.createSequentialGroup()
 .addComponent(xiaoxi, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(ComponentPlacement.UNRELATED)
 .addPreferredGap(ComponentPlacement.RELATED, 173, Short.MAX_VALUE)
 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
 .addComponent(playbtn)
 .addComponent(stopbtn)
 .addComponent(againbtn))
 .addContainerGap())
 );
 contentPane.setLayout(gl_contentPane);
 }
 
}

運行結(jié)果如下:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java輸入字母來判斷星期幾的實現(xiàn)代碼

    Java輸入字母來判斷星期幾的實現(xiàn)代碼

    這篇文章主要介紹了Java輸入字母來判斷星期幾的實現(xiàn)代碼,用情況語句比較好,如果第一個字母一樣,則判斷用情況語句或if語句判斷第二個字母需要的朋友可以參考下
    2017-02-02
  • MyBatis如何使用(二)

    MyBatis如何使用(二)

    這篇文章主要介紹了MyBatis如何使用(二)的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-07-07
  • Mybatis -如何處理clob類型數(shù)據(jù)

    Mybatis -如何處理clob類型數(shù)據(jù)

    這篇文章主要介紹了Mybatis 如何處理clob類型數(shù)據(jù)的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • 如何利用Java實現(xiàn)MySQL的數(shù)據(jù)變化監(jiān)聽

    如何利用Java實現(xiàn)MySQL的數(shù)據(jù)變化監(jiān)聽

    在高并發(fā)和大數(shù)據(jù)環(huán)境下,實時獲取?MySQL?數(shù)據(jù)庫的增量變化對數(shù)據(jù)同步、數(shù)據(jù)分析、緩存更新等場景至關(guān)重要,下面我們就來看看如何通過Java實現(xiàn)MySQL的數(shù)據(jù)變化監(jiān)聽吧
    2025-02-02
  • SpringBoot讀取Resource目錄下文件的四種方式總結(jié)

    SpringBoot讀取Resource目錄下文件的四種方式總結(jié)

    在Spring?Boot項目中,經(jīng)常需要獲取resources目錄下的文件,這些文件可以包括配置文件、模板文件、靜態(tài)資源等,本文將介紹四種常用的方法來獲取resources目錄下的文件,需要的朋友可以參考下
    2023-08-08
  • Maven?Web項目使用Cargo插件實現(xiàn)自動化部署的詳細(xì)步驟

    Maven?Web項目使用Cargo插件實現(xiàn)自動化部署的詳細(xì)步驟

    cargo ,它是一組幫助用戶實現(xiàn)自動化部署,操作Web容器的工具,并且?guī)缀踔С炙械腤eb容器,這篇文章主要介紹了Maven?Web項目使用Cargo實現(xiàn)自動化部署,需要的朋友可以參考下
    2023-02-02
  • 怎樣通過反射獲取非靜態(tài)內(nèi)部類實例

    怎樣通過反射獲取非靜態(tài)內(nèi)部類實例

    這篇文章主要介紹了怎樣通過反射獲取非靜態(tài)內(nèi)部類實例,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Spring MVC文件上傳大小和類型限制以及超大文件上傳bug問題

    Spring MVC文件上傳大小和類型限制以及超大文件上傳bug問題

    這篇文章主要介紹了Spring MVC文件上傳大小和類型限制以及超大文件上傳bug問題,非常具有實用價值,需要的朋友可以參考下
    2017-10-10
  • 超級好用的輕量級JSON處理命令jq(最新推薦)

    超級好用的輕量級JSON處理命令jq(最新推薦)

    jq是一個輕量級的命令行工具,讓你可以非常方便地處理JSON數(shù)據(jù),如切分、過濾、映射、轉(zhuǎn)化等,就像sed、awk、grep文本處理三劍客一樣,這篇文章主要介紹了超級好用的輕量級JSON處理命令jq,需要的朋友可以參考下
    2023-01-01
  • Java8使用stream查找重復(fù)元素的方法示例

    Java8使用stream查找重復(fù)元素的方法示例

    Java?8?是一個非常成功的版本,這個版本新增的Stream,配合同版本出現(xiàn)的Lambda?,給我們操作集合(Collection)提供了極大的便利,Stream流是JDK8新增的成員,本文給大家介紹了Java8使用stream查找重復(fù)元素的方法示例,需要的朋友可以參考下
    2024-04-04

最新評論

漳浦县| 沛县| 遂宁市| 潜山县| 昂仁县| 聂拉木县| 房产| 五指山市| 霍林郭勒市| 正镶白旗| 兰州市| 镇巴县| 梅河口市| 武冈市| 正安县| 太白县| 大港区| 防城港市| 民勤县| 商都县| 镇远县| 内江市| 肇东市| 汉寿县| 永和县| 涟源市| 曲麻莱县| 晋城| 双流县| 剑川县| 武安市| 阿拉善右旗| 金乡县| 和政县| 南华县| 顺昌县| 仁化县| 枞阳县| 汉源县| 咸阳市| 哈巴河县|