import javax.sound.midi.*;
import javax.swing.*;
import java.awt.event.*;
public class BPlay implements ActionListener {
public static void main(String[] args) {
BPlay stereo = new BPlay();
stereo.play();
}
public void play() {
JFrame myfirstFrame = new JFrame();
JButton pl = new JButton("Click me to listen to something");
myfirstFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pl.addActionListener(this);
myfirstFrame.getContentPane().add(pl);
myfirstFrame.setSize(300, 300);
myfirstFrame.setVisible(true);
}
public void actionPerformed(ActionEvent event) {
try {
Sequencer mfpl = MidiSystem.getSequencer();
mfpl.open();
Sequence mfs = new Sequence(Sequence.PPQ, 4);
Track mft = mfs.createTrack();
ShortMessage a = new ShortMessage();
a.setMessage(144, 1, 72, 100);
MidiEvent non = new MidiEvent(a, 1);
mft.add(non);
ShortMessage b = new ShortMessage();
b.setMessage(128, 1, 72, 100);
MidiEvent noff = new MidiEvent(b, 1);
mft.add(noff);
mfpl.setSequence(mfs);
mfpl.start();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
This is my son's first app, how did you like it?