import java.awt.*; import java.awt.event.*; import javax.sound.midi.*; import java.applet.Applet; public class Mandoliin extends Applet{ MidiChannel kanal; int valjus=65; int korgus=60; //C public void paint(Graphics g){ g.setColor(new Color(100, 200, 100)); g.setColor(Color.black); g.drawLine(130, 60, 350, 60); g.drawLine(130, 100, 350, 100); g.drawLine(130, 60, 130, 100); g.drawOval(345, 35, 90, 90); int i=64; for(int a=0; a<4; a++) { g.drawLine(135, i, 375, i); i=i+10; } int o=140; for(int a=0; a<8; a++) { g.drawLine(o, 60, o, 100); o=o+30; } } public Mandoliin(){ try{ addMouseListener(new HiireKuular()); Synthesizer synthesizer=MidiSystem.getSynthesizer(); synthesizer.open(); kanal=synthesizer.getChannels()[0]; //kanal 0; }catch(Exception viga){ System.out.println(viga); } } class HiireKuular extends MouseAdapter{ public void mousePressed(MouseEvent e){ if(e.getX()>140 && e.getX()<355) { if(e.getY()>60 && e.getY()<70) { korgus=76+(e.getX()-155+15)/30-1; kanal.noteOn(korgus, valjus); } if(e.getY()>70 && e.getY()<80) { korgus=69+(e.getX()-155+15)/30-1; kanal.noteOn(korgus, valjus); } if(e.getY()>80 && e.getY()<90) { korgus=62+(e.getX()-155+15)/30-1; kanal.noteOn(korgus, valjus); } if(e.getY()>90 && e.getY()<100) { korgus=55+(e.getX()-155+15)/30-1; kanal.noteOn(korgus, valjus); } } } public void mouseReleased(MouseEvent e){ kanal.noteOff(korgus); } } public static void main(String argumendid[]){ Frame f=new Frame("Vajuta hiirega"); f.setSize(700, 500); f.add(new Mandoliin()); f.setVisible(true); } }