import java.awt.*; import javax.swing.*; import javax.sound.midi.*; import java.util.*; import java.awt.event.*; public class BeatBoxApplet extends JApplet { JPanel mainPanel; ArrayList checkboxList; int bpm = 120; Sequencer sequencer; Sequence sequence; Track track; int numTicks; static final int NUM_INSTRUMENTS=18; String[] instrumentNames = { "Bass Drum", "Closed Hi-Hat", "Open Hi-Hat", "Acoustic Snare", "Crash Cymbal", "Hand Clap", "High Tom", "Hi Bongo", "Maracas", "Whistle", "Low Conga", "Cowbell", "Low-mid Tom", "High Agogo", "Open Hi Conga", "Low Bongo", "Low Floor Tom", "Tambourine" }; int[] instruments = {35,42,46,38,49,39,50,60,70,72,64,56,47,67,63,61,41,54}; JButton[] instrumentButtons; public void init() { Container container = getContentPane(); //dfw BorderLayout layout = new BorderLayout(); JPanel background = new JPanel(layout); background.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); checkboxList = new ArrayList(); Box buttonBox = new Box(BoxLayout.Y_AXIS); JButton start = new JButton("ReStart Loop"); start.addActionListener(new MyStartListener()); buttonBox.add(start); JLabel dummyLabel2 = new JLabel("."); buttonBox.add(dummyLabel2); JButton stop = new JButton("Stop sound"); stop.addActionListener(new MyStopListener()); buttonBox.add(stop); /* JButton upTempo = new JButton("Tempo Up"); upTempo.addActionListener(new MyUpTempoListener()); buttonBox.add(upTempo); JButton downTempo = new JButton("Tempo Down"); downTempo.addActionListener(new MyDownTempoListener()); buttonBox.add(downTempo); */ Box nameBox = new Box(BoxLayout.Y_AXIS); //JLabel dummyLabel = new JLabel("Tick#"); //nameBox.add(dummyLabel); instrumentButtons = new JButton[NUM_INSTRUMENTS+1]; for (int i = 0; i < NUM_INSTRUMENTS; i++) { instrumentButtons[i] = new JButton(instrumentNames[i]); instrumentButtons[i].addActionListener(new InstrumentButtonListener()); nameBox.add(instrumentButtons[i]); } background.add(BorderLayout.EAST, buttonBox); background.add(BorderLayout.WEST, nameBox); container.add(background); //dfw String input = JOptionPane.showInputDialog("Number of ticks per loop","16"); numTicks = Integer.parseInt(input); GridLayout grid = new GridLayout(NUM_INSTRUMENTS+1,numTicks); grid.setVgap(1); grid.setHgap(2); mainPanel = new JPanel(grid); background.add(BorderLayout.CENTER, mainPanel); //for (int i = 1; i <= numTicks; i++) { //first row of grid // JLabel c = new JLabel(""+i); // mainPanel.add(c); //} for (int i=0; i