import javax.sound.midi.*; import java.awt.geom.AffineTransform; import java.awt.*; import java.applet.*; import java.awt.event.*; public class Noot{ public static void main(String argumendid[]) throws Exception{ Frame f=new Frame("Ksülofon"); f.setSize(300, 225); Applet ap=new Transform1(); ap.init(); f.add(ap); f.setVisible(true); // System.exit(0); } } class Transform1 extends Applet implements MouseListener{ Synthesizer synthesizer; MidiChannel kanal; public Transform1(){ try{ synthesizer=MidiSystem.getSynthesizer(); synthesizer.open(); kanal=synthesizer.getChannels()[0]; //kanal 0; }catch(Exception e){} } public void paint(Graphics alggr){ Graphics2D g=(Graphics2D)alggr; g.fillRect(0, 110, 240, 10); g.fillRect(0, 80, 240, 10); g.fillRect(10, 10, 20, 180); g.setColor(Color.green); g.fillRect(40, 20, 20, 160); g.setColor(Color.red); g.fillRect(70, 30, 20, 140); g.setColor(Color.blue); g.fillRect(100, 40, 20, 120); g.setColor(Color.pink); g.fillRect(130, 50, 20, 100); g.setColor(Color.yellow); g.fillRect(160, 60, 20, 80); g.setColor(Color.cyan); g.fillRect(190, 70, 20, 60); g.setColor(Color.orange); g.fillRect(220, 80, 20, 40); addMouseListener(this); } public void mousePressed(MouseEvent e){ int x,y; x=(int)e.getX(); y=(int)e.getY(); //System.out.println(x+", "+y); for (int i=0; i<240; i=i+20){ //System.out.println(((x>10+(i))&&(x<30+(i))&&(y>10+(i/2))&&(y<190+(i/2)))); //System.out.println("i="+i); //if((x>10)&&(x<30)&&(y>10)&&(y<190)){ if((x>10+(i))&&(x<30+(i))&&(y>=10+(i/3))&&(y<=190-(i/3))){ try{ int korgus=67; //A if((x>10)&&(x<30)){ korgus=67; } if((x>40)&&(x<60)){ korgus=69; } if((x>70)&&(x<90)){ korgus=71; } if((x>100)&&(x<120)){ korgus=72; } if((x>130)&&(x<150)){ korgus=74; } if((x>160)&&(x<180)){ korgus=76; } if((x>190)&&(x<210)){ korgus=78; } if((x>220)&&(x<240)){ korgus=79; } int valjus=65; //keskmine kanal.noteOn(korgus, valjus); Thread.sleep(500); kanal.noteOff(korgus); } catch(Exception ex){ ex.printStackTrace(); } } } } public void mouseReleased(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseClicked(MouseEvent e){} }