1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
import javax.swing.*;
import java.awt.event.ActionListener;
class IHMSon extends JPanel implements ActionListener {
private JButton jouer = new JButton("jouer");
private java.applet.AudioClip son;
IHMSon() {
java.net.URL url = null;
try {
url = new java.net.URL("file:///C:/Users/User/Desktop/Java/Enclos9/Kalimba.mp3");
}
catch (java.net.MalformedURLException exc) {
exc.printStackTrace();
}
son = java.applet.Applet.newAudioClip(url);
add(jouer);
jouer.addActionListener(this);
}
public void actionPerformed(java.awt.event.ActionEvent e) {
son.play();
//System.out.println(son);
}
public static void main(String[] argv) {
JFrame fenetre = new JFrame();
fenetre.setContentPane(new IHMSon());
fenetre.pack();
fenetre.setLocation(100, 100);
fenetre.setVisible(true);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} |