import javax.sound.midi.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.Vector; public class Noodirakend5 extends JApplet implements ActionListener{ Sequence sequence; JButton nupp=new JButton("Mängi"); public void init(){ try{ ShortMessage lahti = new ShortMessage(); ShortMessage kinni = new ShortMessage(); ShortMessage algus = new ShortMessage(); algus.setMessage(ShortMessage.PROGRAM_CHANGE, 0, 16, 0); ShortMessage lahti1 = new ShortMessage(); ShortMessage kinni1 = new ShortMessage(); lahti1.setMessage(ShortMessage.NOTE_ON, 0, 60, 93); // 0 kanal, 65 noot, 93 valjus kinni1.setMessage(ShortMessage.NOTE_OFF, 0, 60, 93); ShortMessage lahti2 = new ShortMessage(); ShortMessage kinni2 = new ShortMessage(); lahti2.setMessage(ShortMessage.NOTE_ON, 0, 62, 93); kinni2.setMessage(ShortMessage.NOTE_OFF, 0, 62, 93); ShortMessage lahti3 = new ShortMessage(); ShortMessage kinni3 = new ShortMessage(); lahti3.setMessage(ShortMessage.NOTE_ON, 0, 64, 93); kinni3.setMessage(ShortMessage.NOTE_OFF, 0, 64, 93); ShortMessage lahti4 = new ShortMessage(); ShortMessage kinni4 = new ShortMessage(); lahti4.setMessage(ShortMessage.NOTE_ON, 0, 65, 93); kinni4.setMessage(ShortMessage.NOTE_OFF, 0, 65, 93); ShortMessage lahti5 = new ShortMessage(); ShortMessage kinni5 = new ShortMessage(); lahti5.setMessage(ShortMessage.NOTE_ON, 0, 67, 93); kinni5.setMessage(ShortMessage.NOTE_OFF, 0, 67, 93); ShortMessage lahti6 = new ShortMessage(); ShortMessage kinni6 = new ShortMessage(); lahti6.setMessage(ShortMessage.NOTE_ON, 0, 69, 93); kinni6.setMessage(ShortMessage.NOTE_OFF, 0, 69, 93); ShortMessage lahti7 = new ShortMessage(); ShortMessage kinni7 = new ShortMessage(); lahti7.setMessage(ShortMessage.NOTE_ON, 0, 71, 93); kinni7.setMessage(ShortMessage.NOTE_OFF, 0, 71, 93); ShortMessage lahti8 = new ShortMessage(); ShortMessage kinni8 = new ShortMessage(); lahti8.setMessage(ShortMessage.NOTE_ON, 0, 72, 93); kinni8.setMessage(ShortMessage.NOTE_OFF, 0, 72, 93); sequence=new Sequence(Sequence.PPQ, 4); Track track=sequence.createTrack(); track.add(new MidiEvent(algus, 0)); track.add(new MidiEvent(lahti1, 0)); track.add(new MidiEvent(kinni1, 3)); track.add(new MidiEvent(lahti2, 4)); track.add(new MidiEvent(kinni2, 7)); track.add(new MidiEvent(lahti3, 8)); track.add(new MidiEvent(kinni3, 10)); track.add(new MidiEvent(lahti4, 11)); track.add(new MidiEvent(kinni4, 13)); track.add(new MidiEvent(lahti5, 14)); track.add(new MidiEvent(kinni5, 16)); track.add(new MidiEvent(lahti6, 17)); track.add(new MidiEvent(kinni6, 20)); track.add(new MidiEvent(lahti7, 21)); track.add(new MidiEvent(kinni7, 23)); track.add(new MidiEvent(lahti8, 24)); track.add(new MidiEvent(kinni8, 26)); getContentPane().add(nupp); nupp.addActionListener(this); }catch(Exception e){e.printStackTrace();} } public void actionPerformed(ActionEvent e){ try{ Sequencer sequencer=MidiSystem.getSequencer(); sequencer.open(); sequencer.setSequence(sequence); sequencer.start(); System.out.println("Mängib"); }catch(Exception ex){ ex.printStackTrace(); System.out.println(ex); } } public static void main(String[] argumendid){ Frame f=new Frame(); Noodirakend5 n; f.add(n=new Noodirakend5()); n.init(); f.setSize(200, 200); f.setVisible(true); } }