<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 6  文章 - 129  trackbacks - 0
    <2014年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    常用鏈接

    留言簿(14)

    隨筆檔案(6)

    文章分類(467)

    文章檔案(423)

    相冊

    收藏夾(18)

    JAVA

    搜索

    •  

    積分與排名

    • 積分 - 825404
    • 排名 - 49

    最新評論

    閱讀排行榜

    評論排行榜

    文件來源:http://www.tkk7.com/beansoft/archive/2007/06/27/126550.html
    /*

     * @(#)AudioPlayer.java 1.0 03/04/17
     *
     
    */
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.Applet;
    import java.applet.AudioClip;
    //{{{ Declares!
    class test {
    }
    //}}}
    public class AudioPlayer
        
    extends Frame {
      AudioClip clip 
    = null;
      FileDialog dialog 
    = new FileDialog(this);
      Label labelCopyright 
    = new Label();
      TextField textFieldFileName 
    = new TextField();
      Panel panel1 
    = new Panel();
      Button buttonOpen 
    = new Button();
      Button buttonPlay 
    = new Button();
      Button buttonLoop 
    = new Button();
      Button buttonStop 
    = new Button();

      
    public AudioPlayer() {
        setTitle(
    "AudioPlayer");
        addWindowListener(
    new WindowAdapter() {
          
    public void windowClosing(WindowEvent e) {
            dispose();
            System.exit(
    0);
          }
        }
        );
        
    try {
          jbInit();
        }
        
    catch (Exception e) {
          e.printStackTrace();
        }
        pack();
        setVisible(
    true);
      }

      
    private void jbInit() throws Exception {
        labelCopyright.setBackground(Color.darkGray);
        labelCopyright.setForeground(Color.orange);
        labelCopyright.setText(
            
    "Copyright (c) 2003 BeanSoft Studio. All rights reserved.");
        
    this.setTitle("Java Audio Player");
        textFieldFileName.setEditable(
    false);
        buttonOpen.setLabel(
    "打開");
        buttonOpen.addActionListener(
    new java.awt.event.ActionListener() {
          
    public void actionPerformed(ActionEvent e) {
            buttonOpen_actionPerformed(e);
          }
        }
        );
        buttonPlay.setLabel(
    "播放");
        buttonPlay.addActionListener(
    new java.awt.event.ActionListener() {
          
    public void actionPerformed(ActionEvent e) {
            play();
          }
        }
        );
        buttonLoop.setLabel(
    "循環(huán)");
        buttonLoop.addActionListener(
    new java.awt.event.ActionListener() {
          
    public void actionPerformed(ActionEvent e) {
            loop();
          }
        }
        );
        buttonStop.setLabel(
    "停止");
        buttonStop.addActionListener(
    new java.awt.event.ActionListener() {
          
    public void actionPerformed(ActionEvent e) {
            stop();
          }
        }
        );
        
    this.add(labelCopyright, BorderLayout.SOUTH);
        
    this.add(textFieldFileName, BorderLayout.NORTH);
        
    this.add(panel1, BorderLayout.CENTER);
        panel1.add(buttonOpen, 
    null);
        panel1.add(buttonPlay, 
    null);
        panel1.add(buttonLoop, 
    null);
        panel1.add(buttonStop, 
    null);
      }

      
    public AudioClip getAudioClip() {
        
    return this.clip;
      }

      
    public void setAudioClip(AudioClip clip) {
        
    this.clip = clip;
      }

      
    public static void main(String args[]) {
        
    new AudioPlayer();
      }

      
    void buttonOpen_actionPerformed(ActionEvent e) {
        stop();
        dialog.show();
        
    if (dialog.getFile() != null) {
          String filename 
    = dialog.getDirectory() + dialog.getFile();
          
    try {
            setAudioClip(Applet.newAudioClip( (
    new java.io.File(filename)).toURL()));
          }
          
    catch (Exception ex) {
            ex.printStackTrace();
          }

          textFieldFileName.setText(filename);
        }
        play();
      }

      
    void play() {
        
    if (getAudioClip() != null) {
          getAudioClip().play();
        }
      }

      
    void loop() {
        
    if (getAudioClip() != null) {
          getAudioClip().loop();
        }
      }

      
    void stop() {
        
    if (getAudioClip() != null) {
          getAudioClip().stop();
        }
      }
    }


    posted on 2009-08-06 20:18 Ke 閱讀(1886) 評論(2)  編輯  收藏 所屬分類: java

    FeedBack:
    # re: AWT 練習(xí) - 播放聲音文件 AudioPlayer.java(轉(zhuǎn)) 2013-03-03 22:12 zjut-jiangnan
    謝謝你的代碼,找了好久,看到完整的,能運行的。
    解決了我的Java swing聲音播放問題。  回復(fù)  更多評論
      
    # re: AWT 練習(xí) - 播放聲音文件 AudioPlayer.java(轉(zhuǎn)) 2014-07-24 15:58 學(xué)習(xí)
    樓主好厲害,還是封裝功能本身比較好,其它的實現(xiàn)功能是否有副作用,不過封裝如果不好也不知道會怎么樣,自己實現(xiàn)要想清楚邏輯.  回復(fù)  更多評論
      
    主站蜘蛛池模板: 99999久久久久久亚洲| 无码少妇精品一区二区免费动态| 国产午夜精品久久久久免费视 | 亚洲av麻豆aⅴ无码电影| 亚洲无砖砖区免费| 99久久人妻精品免费二区| 久久亚洲高清观看| 一级一看免费完整版毛片| 亚洲成人影院在线观看| 国产成人 亚洲欧洲| 国产免费观看黄AV片 | 黄床大片30分钟免费看| 妞干网在线免费观看| 亚洲av成人综合网| 成人最新午夜免费视频| 国产成人亚洲精品| 亚洲午夜福利717| 国产一级片免费看| 亚洲人成未满十八禁网站| 最新中文字幕电影免费观看| 大妹子影视剧在线观看全集免费| 亚洲伊人久久成综合人影院| 成在线人直播免费视频| 精品久久香蕉国产线看观看亚洲| 成人看的午夜免费毛片| 日韩电影免费在线观看中文字幕| 亚洲精品无码久久久久久久| 中文字幕无码免费久久99| 亚洲精品无码mⅴ在线观看| 亚洲性线免费观看视频成熟| 亚洲乱码在线观看| 亚洲成av人片天堂网老年人| 成人黄色免费网址| 偷自拍亚洲视频在线观看| 亚洲午夜电影一区二区三区| 国产麻豆剧传媒精品国产免费| 一级黄色免费大片| 欧美激情综合亚洲一二区| 亚洲精品自在在线观看| 精品女同一区二区三区免费站 | 国内精品99亚洲免费高清|