import java.applet.Applet; import java.awt.event.*; import java.awt.*; import javax.sound.midi.*; public class Eksam1a extends Applet implements MouseListener{ MidiChannel kanal; public Eksam1a(){ try{ Synthesizer synthesizer=MidiSystem.getSynthesizer(); synthesizer.open(); kanal=synthesizer.getChannels()[0]; //kanal 0; addMouseListener(this); }catch(Exception viga){ System.out.println("Viga oli"+viga); } } public void paint(Graphics g){ for(int i=0;i<=100;i=i+20){ g.setColor(Color.black); g.drawRect((int)(i+40),50,100,100); } } public void mousePressed(MouseEvent e){ int x=e.getX(); int y=e.getY(); Graphics g=this.getGraphics(); if((x>40) && (x<60)){ if((y>50) &&(y<150)){ kanal.noteOn(60, 65); g.fillRect(40,50,20,100); g.setColor(Color.blue); try{Thread.sleep(50); }catch(Exception f){} repaint(); } } if((x>60) && (x<80)){ if((y>50) &&(y<150)){ kanal.noteOn(61, 65); g.fillRect(60,50,20,100); g.setColor(Color.blue); try{Thread.sleep(50); }catch(Exception f){} repaint(); } } if((x>80) && (x<100)){ if((y>50) &&(y<150)){ kanal.noteOn(62, 65); g.fillRect(80,50,20,100); g.setColor(Color.blue); try{Thread.sleep(50); }catch(Exception f){} repaint(); } } if((x>100) && (x<120)){ if((y>50) &&(y<150)){ kanal.noteOn(63, 65); g.fillRect(100,50,20,100); g.setColor(Color.blue); try{Thread.sleep(50); }catch(Exception f){} repaint(); } } if((x>120) && (x<140)){ if((y>50) &&(y<150)){ kanal.noteOn(64, 65); g.fillRect(120,50,20,100); g.setColor(Color.blue); try{Thread.sleep(50); }catch(Exception f){} repaint(); } } if((x>140) && (x<160)){ if((y>50) &&(y<150)){ kanal.noteOn(65, 65); g.fillRect(140,50,20,100); g.setColor(Color.blue); try{Thread.sleep(50); }catch(Exception f){} repaint(); } } if((x>160) && (x<180)){ if((y>50) &&(y<150)){ kanal.noteOn(67, 65); g.fillRect(160,50,20,100); g.setColor(Color.blue); try{Thread.sleep(50); }catch(Exception f){} repaint(); } } if((x>180) && (x<200)){ if((y>50) &&(y<150)){ kanal.noteOn(69, 65); g.fillRect(180,50,20,100); g.setColor(Color.blue); try{Thread.sleep(50); }catch(Exception f){} repaint(); } } if((x>200) && (x<220)){ if((y>50) &&(y<150)){ kanal.noteOn(70, 65); g.fillRect(200,50,20,100); g.setColor(Color.blue); try{Thread.sleep(50); }catch(Exception f){} repaint(); } } if((x>220) && (x<240)){ if((y>50) &&(y<150)){ kanal.noteOn(71, 65); g.fillRect(220,50,20,100); g.setColor(Color.blue); try{Thread.sleep(50); }catch(Exception f){} repaint(); } } } public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseClicked(MouseEvent e){} public static void main(String argumendid[]){ Frame f=new Frame("Ksülofon"); f.add(new Eksam1a()); f.setSize(300, 300); f.setVisible(true); f.addWindowListener(new Raami2kuular()); } } class Raami2kuular extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.exit(0); } }