import java.applet.Applet; import java.awt.*; import java.awt.event.*; import javax.sound.midi.*; public class kolmkola extends Applet implements ItemListener{ MidiChannel kanal,kanal1,kanal2; TextField tf=new TextField("100",10); Choice v=new Choice(); public kolmkola (){ v.add("Do"); v.add("Re"); v.add("Mi"); v.add("Fa"); v.add("Sol"); v.add("La"); v.add("Si"); add(v); v.addItemListener(this); try{ Synthesizer synthesizer=MidiSystem.getSynthesizer(); synthesizer.open(); kanal=synthesizer.getChannels()[0]; kanal1=synthesizer.getChannels()[1]; kanal2=synthesizer.getChannels()[2]; kanal.programChange(1, 1); kanal1.programChange(1, 1); kanal2.programChange(1, 1);} catch (Exception viga){} } public void mangi(int toon){ try{ kanal.noteOn(60+toon, 255); kanal1.noteOn(64+toon, 255); kanal2.noteOn(67+toon, 255); Thread.sleep(400); kanal.noteOff(60+toon); kanal1.noteOff(64+toon); kanal2.noteOff(67+toon); }catch(Exception w){}; } public void itemStateChanged(ItemEvent e){ int toon=0; String valik2=v.getSelectedItem(); if(valik2.equals("Do"))toon=1; if(valik2.equals("Re"))toon=3; if(valik2.equals("Mi"))toon=5; if(valik2.equals("Fa"))toon=6; if(valik2.equals("Sol"))toon=8; if(valik2.equals("La"))toon=10; if(valik2.equals("Si"))toon=12; mangi(toon); } public static void main(String argumendid[]) throws Exception{ Frame f=new Frame("Klaver"); f.setSize(200, 200); f.add(new kolmkola()); f.setVisible(true); f.addWindowListener(new Kinni()); } } class Kinni extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.exit(0); } }