0

I would like there to be several buttons in this GUI to play multiple sounds while at the same time editing a text file so the next time the program runs the songs playing upon closing are still playing. I've gotten to one song so far but it won't open and give me this error. I haven't been coding java for that long so I think its something stupid that I've missed. enter image description here

The code

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;

public class AddSound extends JFrame {
    JButton Play = new JButton("Play");
    JButton Loop = new JButton("Loop");
    JButton Stop = new JButton("Stop");

    URL music1 = AddSound.class.getResource("music1.wav");
    AudioClip clip = Applet.newAudioClip(music1);

    public AddSound() {
        super("AddingSound");
        setLayout(new FlowLayout());

        Play.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                clip.play();
            }

        });

        Loop.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                clip.loop();
            }

        });

        Stop.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                clip.stop();
            }

        });
        add(Play);
        add(Loop);
        add(Stop);
    }

    public static void main(String args[]) {
        JFrame frame = new AddSound();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(90, 90);
        frame.setVisible(true);
    }
}
cosmichero2025
  • 1,029
  • 4
  • 14
  • 37

0 Answers0