/*
 * 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.midi.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;


public class URLMidi extends Frame {
    
       Sequence suara;
       Sequencer ambilSuara;
       
       public URL getURL(String namaFile){
              URL url=null;
              try{
                    url=this.getClass().getResource(namaFile);
              }catch(Exception e){}
              return url;
       }
       URLMidi(){
             try {
                    suara = MidiSystem.getSequence(getURL("flourish.mid"));
                    ambilSuara=MidiSystem.getSequencer();
                    ambilSuara.setSequence(suara);
                    ambilSuara.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
                    ambilSuara.open();
                    ambilSuara.start();
              } catch (InvalidMidiDataException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
              } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
              } catch (MidiUnavailableException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
              }
              setTitle("Test URL MIDI");
              setSize(300,200);
              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("Resolution : "+suara.getResolution(), 10, 50);
            g.drawString("Tick length : " + suara.getTickLength(), 10, 100);
            g.drawString("Tracks: " + suara.getTracks().length, 10, 150);
        }
        
        public static void main(String [] dhafiq){
            new URLMidi();
        }
}

       
