Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PlaySounds {
- private AudioInputStream audioStream;
- public static Clip clip;
- private URL url;
- public static int nextSound;
- public void playAllSounds() {
- for (String str : soundList) { // arrayList of sounds
- str = soundList.get(nextSound);
- url = getClass().getResource(str);
- }
- try {
- audioStream = AudioSystem.getAudioInputStream(url);
- clip = AudioSystem.getClip();
- clip.open(audioStream);
- clip.start();
- } catch (Exception e) {
- }
- }
- }
- PlaySounds ps = new PlaySounds();
- int next = 0;
- List<Integer> positions = new ArrayList<>();
- /*Some other methods....
- ....
- */
- private void getshuffledPositions() {
- for (int i = 0, i <=12; i++) {
- positions.add(i);
- }
- Collections.shuffle(positions);
- }
- public void actionPerformed(ActionEvent ae) {
- if (ae.getSource() == playButton) {
- //Some codes.....Here I tried boolean flag, etc
- ps.nextSound = positions.get(next);
- ps.playAllSounds();
- //Some more codes.....
Add Comment
Please, Sign In to add comment