/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



/**
 *
 * @author dhafiq
 */
import java.awt.Graphics;
import java.io.IOException;
import java.net.URL;
import javax.sound.sampled.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Suara extends Frame {
       AudioInputStream suara;
       String eror1="Tidak Ada Eror";
       String eror2="Tidak Ada Eror";
       String eror3="Tidak Ada Eror";
       public URL getURL(String namaFile){
              URL url=null;
              try{
                    url=this.getClass().getResource(namaFile);
              }catch(Exception e){}
              return url;
       }
       Suara(){
              try {
                    suara = AudioSystem.getAudioInputStream(getURL("desktop-login-ubuntu.WAV"));
                    Clip klip =AudioSystem.getClip();
                    klip.open(suara);
                    klip.loop(0);
              } catch (UnsupportedAudioFileException e) {
                    eror1=e.toString();
              } catch (IOException e) {
                    eror2=e.toString();
              } catch (LineUnavailableException e) {
                    eror3=e.toString();
              }
            setTitle("Test Suara");
            setSize(500,500);
            setVisible(true);
            //setDefaultCloseOperation(this.EXIT_ON_CLOSE);
            
         //untuk membuat action close program
         addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e){
                System.exit(0);
            }
        });
      }
       
      public void paint(Graphics g){
            g.drawString(suara.getFormat().toString(), 10, 50);
            g.drawString("Rate: " + (int)suara.getFormat().getSampleRate(), 10, 100);
            g.drawString("Channels: " + suara.getFormat().getChannels(), 10, 150);
            g.drawString("Encoded format: " + suara.getFormat().getEncoding().toString(), 10, 200);
            g.drawString("Size: " + suara.getFormat().getSampleSizeInBits() + "-bit", 10,250);
            g.drawString("Frame size: " + suara.getFormat().getFrameSize(), 10, 300);
            g.drawString("Eror 1 : "+eror1, 10, 350);
            g.drawString("Eror 2 : "+eror2, 10, 400);
            g.drawString("Eror 3 : "+eror3, 10, 450);
      }
      public static void main(String [] dhafiq){
            new Suara();
      }
}

