Java windowbuilder在一个窗口中显示多个音频文件

Java windowbuilder在一个窗口中显示多个音频文件,java,eclipse,audio,windowbuilder,Java,Eclipse,Audio,Windowbuilder,我有一个关于我的代码的问题,首先是关于它将发生什么的一些预先信息 我的一位平面设计朋友在她的大学举办了一个展览/项目,用声学药物影响ppl(展览主题是药物…) 她希望有一个界面,用户可以按下一个按钮,听声音药物。此外,用户应该有机会将kokain和海洛因的声音混合起来,并通过重新按下每个按钮或仅一个按钮停止一个标题来停止所有声音 我的代码有以下问题。在我调试代码的时候,我的第二个监听按钮没有显示,你必须按下窗口的左边按钮,按钮是可见的,你可以启动一个标题并停止它,但是如果你同时播放两个声音,你可

我有一个关于我的代码的问题,首先是关于它将发生什么的一些预先信息

我的一位平面设计朋友在她的大学举办了一个展览/项目,用声学药物影响ppl(展览主题是药物…)

她希望有一个界面,用户可以按下一个按钮,听声音药物。此外,用户应该有机会将kokain和海洛因的声音混合起来,并通过重新按下每个按钮或仅一个按钮停止一个标题来停止所有声音

我的代码有以下问题。在我调试代码的时候,我的第二个监听按钮没有显示,你必须按下窗口的左边按钮,按钮是可见的,你可以启动一个标题并停止它,但是如果你同时播放两个声音,你可以停止一个,如果你停止第二个,它显示它停止了,但实际上没有

如果有人能帮我,我会很高兴的

代码如下:

package test;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JButton;
import javax.swing.JFrame;


public class c extends JFrame {

  String lsd="/Users/shaggy/Desktop/Lsd.wav";  
  JButton btnPlaySoundLSD=new JButton("Listen");
  Clip clip = null;

  String koka ="/Users/shaggy/Desktop/Kokain.wav";
  JButton btnPlaySoundKokain=new JButton("Listen");


public c(){
  btnPlaySoundLSD.setBounds(0, 0, 250, 240);

  btnPlaySoundLSD.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
              JButton b=(JButton)arg0.getSource();
              // play the sound clip
              if(b.getText().equals("Listen")){
                b.setText("Stop");
                btnPlaySoundCLickLSD();
              } else if(btnPlaySoundLSD.getText().equals("Stop")) {
                  b.setText("Listen");
                  clip.stop();
              }
            } catch (LineUnavailableException | IOException
                    | UnsupportedAudioFileException e) {
                e.printStackTrace();
            }
    }
});

  setSize(500, 500);
  getContentPane().setLayout(null);
  getContentPane().add(btnPlaySoundLSD);
  setVisible(true);


    btnPlaySoundKokain.setBounds(0, 238, 250, 240);

    btnPlaySoundKokain.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg1) {
                try {
                  JButton b=(JButton)arg1.getSource();
                  // play the sound clip
                  if(b.getText().equals("Listen")){
                    b.setText("Stop");
                    btnPlaySoundCLickKokain();
                  }     else if(btnPlaySoundKokain.getText().equals("Stop")) {
                  b.setText("Listen");
                  clip.stop();
              }
            } catch (LineUnavailableException | IOException
                    | UnsupportedAudioFileException e) {
                e.printStackTrace();
            }
        }
    });

  setSize(500, 500);
  getContentPane().setLayout(null);
  getContentPane().add(btnPlaySoundKokain);
  setVisible(true);
}


private void btnPlaySoundCLickKokain() throws     LineUnavailableException, IOException, UnsupportedAudioFileException{ 

  File soundFile = new File(koka);
  AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);

  DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());
  clip = (Clip) AudioSystem.getLine(info);
  clip.open(sound);

  clip.addLineListener(new LineListener() {
  public void update(LineEvent event) {
    if (event.getType() == LineEvent.Type.STOP) {
    System.out.println("stop");
      event.getLine().close();
    }
  }
  });

  clip.start();

}


private void btnPlaySoundCLickLSD() throws LineUnavailableException,     IOException, UnsupportedAudioFileException{ 

  File soundFile = new File(lsd);
  AudioInputStream sound =     AudioSystem.getAudioInputStream(soundFile);

  DataLine.Info info = new DataLine.Info(Clip.class,     sound.getFormat());
  clip = (Clip) AudioSystem.getLine(info);
  clip.open(sound);

  clip.addLineListener(new LineListener() {
  public void update(LineEvent event) {
    if (event.getType() == LineEvent.Type.STOP) {
    System.out.println("stop");
      event.getLine().close();
    }
  }
  });

  clip.start();
}


public static void main(String[] args) {
    c cc=new c();
}

}