import javax.sound.midi.*; import javax.swing.*; import java.awt.event.*; public class OmaPill extends JPanel implements MouseListener{ Synthesizer syntesaator; MidiChannel kanal; int valjus=70; int minkorgus=40; int maxkorgus=100; int noot1; public OmaPill(){ try{ syntesaator=MidiSystem.getSynthesizer(); syntesaator.open(); kanal=syntesaator.getChannels()[0]; addMouseListener(this); }catch(Exception ex){ex.printStackTrace();} } public void mousePressed(MouseEvent e){ int yvahe=getHeight()/(maxkorgus-minkorgus); noot1=minkorgus+e.getY()/yvahe; kanal.noteOn(noot1, valjus); /* Muutke nõnda, et hiirele ülalapool vastaks kõrgem heli Korraga kõlab kaks heli, teine sõltub x-koordinaadist */ } public void mouseReleased(MouseEvent e){ kanal.noteOff(noot1); } public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public static void main(String[] arg){ JFrame f=new JFrame("Pill"); f.add(new OmaPill()); f.setSize(300, 300); f.setVisible(true); } }