hello i want to stop the music after pressing other song i tryed much different ways of doing it but no results please anyone help me i have this code ...
package passwordsaver1;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.net.URL;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.JOptionPane;
/**
*
* @author EXTREME
*/
public final class Music extends javax.swing.JFrame {
void centreWindow() {
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x = (int) ((dimension.getWidth() - getWidth()) / 2);
int y = (int) ((dimension.getHeight() - getHeight()) / 2);
setLocation(x, y);
}
/**
* Creates new form Music
*/
public Music(String mainAccName) {
initComponents();
centreWindow();
setTitle("PasswordSaver - Music");
this.mainAccName = mainAccName;
}
String mainAccName;
private void pitbullActionPerformed(java.awt.event.ActionEvent evt) {
new Thread(new PitBull()).start();
new Thread(new StartCount()).start();
}
private void afrojackActionPerformed(java.awt.event.ActionEvent evt) {
new Thread(new Afrojack()).start();
new Thread(new StartCount()).start();
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Music.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Music.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Music.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Music.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
//new Music().setVisible(true);
}
});
}
private class StartCount implements Runnable {
@Override
public void run() {
for (int x = 0; x < 101; x++) {
ProgressBar.setValue(x);
ProgressBar.repaint();
try {
Thread.sleep(180);
} catch (Exception ex) {
}
}
}
}
class Afrojack implements Runnable {
@Override
public void run() {
try {
URL url = new URL("http://mini-mk-market.com/music/Afrojack.wav");
Clip clip = AudioSystem.getClip();
AudioInputStream ais;
ais = AudioSystem.getAudioInputStream(url);
clip.open(ais);
clip.start();
clip.loop(-1);
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Can't find Internet Connection !");
}
}
}
public void stop() {
try {
URL url = new URL("http://mini-mk-market.com/music/PitBulll.wav");
Clip clip = AudioSystem.getClip();
AudioInputStream ais;
ais = AudioSystem.getAudioInputStream(url);
clip.stop();
} catch (Exception ex) {
//Logger.getLogger(Music.class.getName()).log(Level.SEVERE, null, ex);
}
}
class PitBull implements Runnable {
@Override
public void run() {
try {
URL url = new URL("http://mini-mk-market.com/music/PitBulll.wav");
Clip clip = AudioSystem.getClip();
AudioInputStream ais;
ais = AudioSystem.getAudioInputStream(url);
clip.open(ais);
clip.loop(-1);
clip.start();
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Can't find Internet Connection !");
}
}
}