package hf;
import javax.sound.midi.*;
public class BeatBox1
{
public static void main(String[] args)
{
BeatBox1 boom = new BeatBox1();
boom.go();
}
public void go()
{
try
{
Sequencer player = MidiSystem.getSequencer();
player.open();
Sequence seq = new Sequence(Sequence.PPQ,4);
Track track = seq.createTrack();
for(int i = 5;i<125;i+=5)
{
track.add(makeEvent(144,i,i));
track.add(makeEvent(128,i,i+2));
}
player.setSequence(seq);
player.start();
}
catch(Exception e)
{
System.out.println("Problem starting the BeatBox");
}
}
public static MidiEvent makeEvent(int onOff,int note,int time)
{
MidiEvent event = null;
try
{
ShortMessage a = new ShortMessage();
a.setMessage(onOff,1,note,100);
event = new MidiEvent(a,time);
return event;
}
catch(Exception e)
{
System.out.println("Error in creating Event.");
}
return event;
}
}
我发现了一本书,上面的示例代码。 他们建议作出makeEvent方法是静态的。 是什么原因?
当makeEvent()是由非静态以及该程序正常运行。 有没有办法,可以通过使静态方法来获得任何性能增益或优势?