import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.applet.Applet; import javax.sound.midi.*; public class exam extends Applet{ MidiChannel kanal; int valjus=65; int korgus=60; public exam(){ try{ addMouseListener(new HiireKuular()); Synthesizer synthesizer=MidiSystem.getSynthesizer(); synthesizer.open(); kanal=synthesizer.getChannels()[0]; }catch(Exception viga){ System.out.println(viga); } } public void paint (Graphics a){ a.setColor(Color.red); a.drawRect(50,50,50,50); a.setColor(Color.green); a.drawRect(50,125,50,50); a.setColor(Color.blue); a.drawRect(50,200,50,50); } class HiireKuular extends MouseAdapter{ public void mousePressed(MouseEvent e){ if(e.getX()>50 && e.getX()<100 && e.getY()>50 && e.getY()<100){ Graphics g=exam.this.getGraphics(); g.setColor(Color.white); g.fillRect(0,0,300,300); g.setColor(Color.green); g.drawRect(50,125,50,50); g.setColor(Color.blue); g.drawRect(50,200,50,50); g.setColor(Color.red); g.fillRect(50,50,50,50); g.drawRect(50, e.getY(), 0, 0); } if(e.getX()>50 && e.getX()<100 && e.getY()>125 && e.getY()<175){ Graphics g=exam.this.getGraphics(); g.setColor(Color.white); g.fillRect(0,0,300,300); g.setColor(Color.red); g.drawRect(50,50,50,50); g.setColor(Color.blue); g.drawRect(50,200,50,50); g.setColor(Color.green); g.fillRect(50,125,50,50); g.drawRect(50, e.getY(), 0, 0); } if(e.getX()>50 && e.getX()<100 && e.getY()>200 && e.getY()<250){ Graphics g=exam.this.getGraphics(); g.setColor(Color.white); g.fillRect(0,0,300,300); g.setColor(Color.red); g.drawRect(50,50,50,50); g.setColor(Color.green); g.drawRect(50,125,50,50); g.setColor(Color.blue); g.fillRect(50,200,50,50); g.drawRect(50, e.getY(), 0, 0); } korgus=127-e.getY()/5; kanal.noteOn(korgus, valjus); } public void mouseReleased(MouseEvent e){ kanal.noteOff(korgus); } } public static void main(String argumendid[]){ Frame f=new Frame("Exam"); f.setSize(500, 500); f.setLocation(300,300); f.add(new exam()); f.setVisible(true); }}