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); lahti.setMessage(ShortMessage.NOTE_ON, 0, 65, 93); kinni.setMessage(ShortMessage.NOTE_OFF, 0, 65, 93); sequence=new Sequence(Sequence.PPQ, 4); Track track=sequence.createTrack(); track.add(new MidiEvent(algus, 0)); track.add(new MidiEvent(lahti, 0)); track.add(new MidiEvent(kinni, 4)); track.add(new MidiEvent(lahti, 8)); track.add(new MidiEvent(kinni, 11)); track.add(new MidiEvent(lahti, 12)); track.add(new MidiEvent(kinni, 15)); track.add(new MidiEvent(lahti, 16)); track.add(new MidiEvent(kinni, 31)); 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(); }catch(Exception ex){ ex.printStackTrace(); System.out.println(ex); } } }