import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.applet.*;

public class TesteDeSom extends Frame implements ItemListener, ActionListener 
{
  AudioClip clip;
  List sons;
  Panel p1, p2;
  Button b1;
  public TesteDeSom()
  {
    addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});
    setSize(300,200); 
    sons = new List(5, false);
    sons.addItem("1");
    sons.addItem("2");
    sons.addItem("3");
    sons.addItem("4");
    sons.addItem("5");   
    sons.addItem("6");   
    sons.addItemListener(this);
    p1 = new Panel();
    p1.add(sons);
    add("Center",p1);
    p2 = new Panel();
    b1 = new Button("Sair");
    b1.addActionListener(this); 
    p2.add(b1);
    add("South", p2);    
  }

  public void itemStateChanged(ItemEvent e) 
  {
    String escolha = sons.getSelectedItem();
    String som;

    if (escolha.equals("1"))
      som = "1.wav"; 
    else if (escolha.equals("2"))
      som = "2.wav"; 
    else if (escolha.equals("3"))
      som = "3.wav"; 
    else if (escolha.equals("4"))
      som = "4.wav"; 
    else if (escolha.equals("5"))
      som = "5.wav";      
    else if (escolha.equals("6"))
      som = "6.wav";            
    else som = "eitcha.wav"; 
    System.out.println(escolha);
    System.out.println(System.getProperty("user.dir") + "/"+som);
    if (som != null) 
    {
      try 
      {
        clip = Applet.newAudioClip(new URL("file:" + System.getProperty("user.dir") + "/"+som));
        clip.play();
      }
      catch (MalformedURLException eitcha) 
      {
        System.out.println("Erro na abertura do arquivo");
      }
    }
  }

  public void actionPerformed(ActionEvent e)
  {
    String comando = e.getActionCommand();
    if (comando.equals("Sair"))
      System.exit(0);
  }

  public static void main(String args[]) 
  {
    TesteDeSom f = new TesteDeSom();
    f.setVisible(true);
  }
}
