Minor Error?
I am trying to get my program to print out a grid of checkmarks properly, but since there are so many, they over lap, making them hard to select. How do I get the grid to be spaced out more, or even better, to scroll along on a grid?
Here is the WHOLE program. It compiles. The checkmarks are overlapping on each other. I also tried a grid theat was 17 x 64, and that worked 'ok', but I would like them spaced out and on s scroller...
import java.awt.*;
import javax.swing.*;
import javax.sound.midi.*;
import java.util.*;
import java.awt.event.*;
publicclass BeatBox2
{JPanel mainPanel;
ArrayList < JCheckBox > checkboxList;
Sequencer sequencer;
Sequence sequence;
Track track;
JFrame theFrame;
ScrollPane scroller;
String[] instrumentNames ={"Brass Drum","High Snare","Mid Fade Snare","Mid-Low Snare","High Agogo","Low Agogo","Acoustic Snare",
"Crash Symbol","Closed Hi-Hat","High Tom","Hi Bongo","Maracas",
"Open Hi Conga","Low Conga","Vibraslap","Low-mid Tom","Chirp"};
int[] instruments ={35, 47, 45, 43, 67, 68, 38, 49, 47, 50, 60,
70, 63, 64, 58, 42, 52};
publicstaticvoid main(String[] args)
{new BeatBox2().buildGUI();
}
publicvoid buildGUI()
{theFrame =new JFrame("Ace BeatBox");
theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
BorderLayout layout =new BorderLayout();
JPanel background =new JPanel(layout);
background.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
// ^javax.swing.JPanel[,0,0,0x0,invalid,layout=java.awt.BorderLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.border.EmptyBorder@186768e,flags=9,maximumSize=,minimumSize=,preferredSize=]
checkboxList =new ArrayList<JCheckBox>();
Box buttonBox =new Box(BoxLayout.X_AXIS);
JButton start =new JButton ("Start");
start.addActionListener(new MyStartListener());
buttonBox.add(start);
JButton stop =new JButton ("Stop");
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);
for (int i = 0; i < 17; i++)
nameBox.add(new Label (instrumentNames[i]));
background.add(BorderLayout.NORTH, buttonBox);
background.add(BorderLayout.WEST, nameBox);
theFrame.getContentPane().add(background);
GridLayout grid =new GridLayout(17, 128);
scroller =new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
scroller.getVAdjustable().setUnitIncrement(6);
grid.setVgap(1);
grid.setHgap(1);
mainPanel =new JPanel(grid);// I know I am not doing something right
scroller.add(mainPanel);// somewhere around here...
background.add(BorderLayout.CENTER, mainPanel);
for (int i = 0; i < 2176; i++)
{JCheckBox c =new JCheckBox();
c.setSelected(false);
checkboxList.add(c);
mainPanel.add(c);
}
setUpMidi();
theFrame.setBounds(50, 50, 300, 300);
theFrame.pack();
theFrame.setVisible(true);
}
publicvoid setUpMidi()
{try
{sequencer = MidiSystem.getSequencer();
sequencer.open();
sequence =new Sequence(Sequence.PPQ, 4);
track = sequence.createTrack();
sequencer.setTempoInBPM(120);
}
catch(Exception e){e.printStackTrace();}
}
publicvoid buildTrackAndStart()
{int[] trackList =null;
sequence.deleteTrack(track);
track = sequence.createTrack();
for (int i = 0; i<17; i++)
{trackList =newint[128];
int key = instruments[i];
for (int j = 0; j< 128; j++)
{JCheckBox jc = (JCheckBox) checkboxList.get(j + (128 * i));
if (jc.isSelected())
trackList[j] = key;
else
trackList[j] = 0;
}
makeTracks(trackList);
track.add(makeEvent(176,1,127,0,16));
}
track.add(makeEvent(192,9,1,0,15));
try
{sequencer.setSequence(sequence);
sequencer.setLoopCount(sequencer.LOOP_CONTINUOUSLY);
sequencer.start();
sequencer.setTempoInBPM(120);
}
catch(Exception e){e.printStackTrace();}
}
publicclass MyStartListenerimplements ActionListener
{publicvoid actionPerformed(ActionEvent a)
{buildTrackAndStart();
}
}
publicclass MyStopListenerimplements ActionListener
{publicvoid actionPerformed(ActionEvent a)
{sequencer.stop();
}
}
publicclass MyUpTempoListenerimplements ActionListener
{publicvoid actionPerformed(ActionEvent a)
{float tempoFactor = sequencer.getTempoFactor();
{sequencer.setTempoFactor((float)(tempoFactor * 1.03));
}
}
}
publicclass MyDownTempoListenerimplements ActionListener
{publicvoid actionPerformed(ActionEvent a)
{float tempoFactor = sequencer.getTempoFactor();
{sequencer.setTempoFactor((float)(tempoFactor * .97));
}
}
}
publicvoid makeTracks(int[] list)
{for (int i = 0; i < 128; i++)
{int key = list[i];
if (key != 0)
{track.add(makeEvent(144,9,key, 100, i));
track.add(makeEvent(128,9,key, 100, i + 1));
}
}
}
public MidiEvent makeEvent(int comd,int chan,int one,int two,int tick)
{MidiEvent event =null;
try
{ShortMessage a =new ShortMessage();
a.setMessage(comd, chan, one, two);
event =new MidiEvent(a, tick);
}catch(Exception e)
{ e.printStackTrace();
}
return event;
}
}

