Jump to content

Regarding for Java Applet Drumkit

Recommended Posts

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());


    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());


private class ButtonListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == snareButton)
        if (e.getSource() == hiHatButton)
        if (e.getSource() == bassButton)
        if (e.getSource() == cymbalsButton)


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy