shivambhatele Posted June 16, 2022 Report Share Posted June 16, 2022 Hello All, I am a beginner coder and I am trying to get a java drum kit program that I found by online source, because I thought it would be fun to work with, but when I compile the code on interviewbit the applet comes up with the buttons but no sound plays. I do not know why this is and I was wondering if I could get help fixing it. Can anyone now how to fix this please explain in layman's terms. This is my code: import java.awt.*; import java.applet.*; import java.awt.event.*; import javax.swing.*; public class FinalProjectst extends JApplet { private JButton snareButton; private JButton hiHatButton; private JButton bassButton; private JButton cymbalsButton; private AudioClip snare; private AudioClip hiHat; private AudioClip bass; private AudioClip cymbals; public void init() { setLayout (new FlowLayout()); sampleButtons(); snare = getAudioClip(getDocumentBase(), "Snare.wav"); hiHat = getAudioClip(getDocumentBase(), "HiHat.wav"); bass = getAudioClip(getDocumentBase(), "Kick.wav"); cymbals = getAudioClip(getDocumentBase(), "Crash.wav"); } private void sampleButtons() { snareButton = new JButton("Snare"); hiHatButton = new JButton("Hi Hat"); bassButton = new JButton("Kick"); cymbalsButton = new JButton("Cymbals"); snareButton.addActionListener(new ButtonListener()); hiHatButton.addActionListener(new ButtonListener()); bassButton.addActionListener(new ButtonListener()); cymbalsButton.addActionListener(new ButtonListener()); add(snareButton); add(hiHatButton); add(bassButton); add(cymbalsButton); } private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (e.getSource() == snareButton) snare.play(); if (e.getSource() == hiHatButton) hiHat.play(); if (e.getSource() == bassButton) bass.play(); if (e.getSource() == cymbalsButton) cymbals.play(); } } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.