Java LAB11#2

import java.applet.Applet;

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

import java.applet.AudioClip;

import java.awt.BorderLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.File;

import javax.swing.*;

 

/**

 *

 * @author bankster

 */

public class sound extends Applet implements ActionListener {

 

    JButton btn1, btn2, btn3, btnopen;

    JPanel p;

    JFileChooser jf;

    AudioClip sound;

 

    @Override

    public void init() {

        btnopen = new JButton(”Choose an Audio File”);

        btn1 = new JButton(”PLay”);

        btn2 = new JButton(”Loop”);

        btn3 = new JButton(”Stop”);

 

        btnopen.addActionListener(this);

        btn1.addActionListener(this);

        btn2.addActionListener(this);

        btn3.addActionListener(this);

 

        p = new JPanel();

        p.add(btn1);

        p.add(btn2);

        p.add(btn3);

        add(btnopen, BorderLayout.NORTH);

        add(p, BorderLayout.SOUTH);

        setSize(300, 300);

    }

 

    public void actionPerformed(ActionEvent e) {

        String cmd=e.getActionCommand();

         if(cmd.equalsIgnoreCase(”Choose an Audio File”)){

            JFileChooser jf = new JFileChooser();

            jf.showOpenDialog(this);

            File f = jf.getSelectedFile();

            sound = getAudioClip(getDocumentBase(), f.getName());

 

        }

        else if (cmd.equalsIgnoreCase(”Play”)) {

            sound.play();

        }

        else if(cmd.equalsIgnoreCase(”Loop”)){

            sound.loop();

        }

        else if(cmd.equalsIgnoreCase(”Stop”)){

            sound.stop();

        }

    }

}

Tags: , , , ,

This entry was posted on Wednesday, September 10th, 2008 at 3:17 pm and is filed under java. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Java LAB11#2”

  1. admin Says:

    ทดสอบ comment ครับ

Leave a Reply