import javax.sound.midi.*; //import java.awt.geom.AffineTransform; import java.awt.image.*; import java.awt.*; import java.applet.*; import java.awt.event.*; import java.awt.geom.*; public class Noot{ public static void main(String argumendid[]) throws Exception{ Frame f=new Frame("Ksülo"); f.setSize(330, 360); f.setLocation(50, 50); Applet ap=new Transform1(); ap.init(); f.add(ap); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); f.setResizable(false); f.setVisible(true); //System.exit(0); } } class Transform1 extends Applet implements MouseListener, KeyListener, ItemListener{ int all; boolean yles=true; boolean yles1=true; boolean yles2=true; boolean yles3=true; boolean yles4=true; boolean yles5=true; boolean yles6=true; boolean yles7=true; boolean yles8=true; boolean yles9=true; Synthesizer synthesizer; MidiChannel kanal; int korgus; //A Choice valik=new Choice(); BufferedImage bi=new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB); TexturePaint tp; Ellipse2D el=new Ellipse2D.Float(15,253, 12,6); Ellipse2D el1=new Ellipse2D.Float(45,250, 12,6); Ellipse2D el2=new Ellipse2D.Float(75,247, 12,6); Ellipse2D el3=new Ellipse2D.Float(105,244, 12,6); Ellipse2D el4=new Ellipse2D.Float(135,241, 12,6); Ellipse2D el5=new Ellipse2D.Float(165,238, 12,6); Ellipse2D el6=new Ellipse2D.Float(195,235, 12,6); Ellipse2D el7=new Ellipse2D.Float(225,232, 12,6); Ellipse2D el8=new Ellipse2D.Float(255,229, 12,6); Ellipse2D el9=new Ellipse2D.Float(275,226, 12,6); Shape kujundid[]={el, el1, el2, el3, el4, el5, el6, el7, el8, el9}; public Transform1(){ Graphics2D big=bi.createGraphics(); big.setColor(Color.gray); big.fillRect(0, 0, 20, 20); tp=new TexturePaint(bi, new Rectangle(0, 0, 20, 30)); valik.addItem("TORU"); valik.addItem("VIIUL"); valik.addItem("KLAVER"); valik.addItem("KSÜLO"); valik.addItem("KITARR"); setLayout(null); valik.setLocation(240, 0); add(valik); try{ synthesizer=MidiSystem.getSynthesizer(); synthesizer.open(); kanal=synthesizer.getChannels()[0]; //kanal 0; Instrument[] pillid=synthesizer.getDefaultSoundbank().getInstruments(); kanal.programChange(pillid[67].getPatch().getBank(), pillid[67].getPatch().getProgram()); }catch(Exception e){} } public void init(){ addKeyListener(this); requestFocus(); valik.addItemListener(this); } public void itemStateChanged(ItemEvent e){ Instrument[] pillid=synthesizer.getDefaultSoundbank().getInstruments(); Choice valik1=(Choice)e.getSource(); String pill=valik1.getSelectedItem(); if(pill.equals("VIIUL")) kanal.programChange(pillid[48].getPatch().getBank(), pillid[48].getPatch().getProgram()); if(pill.equals("TORU")) kanal.programChange(pillid[67].getPatch().getBank(), pillid[67].getPatch().getProgram()); if(pill.equals("KSÜLO")) kanal.programChange(pillid[12].getPatch().getBank(), pillid[12].getPatch().getProgram()); if(pill.equals("KLAVER")) kanal.programChange(pillid[0].getPatch().getBank(), pillid[0].getPatch().getProgram()); if(pill.equals("KITARR")) kanal.programChange(pillid[24].getPatch().getBank(), pillid[24].getPatch().getProgram()); requestFocus(); } public void paint(Graphics alggr){ Graphics2D g=(Graphics2D)alggr; Rectangle2D r1=new Rectangle2D.Float(0, 0, 400, 400); g.setPaint(tp); g.fill(r1); g.setColor(Color.black); g.fillRect(0, 110, 240, 10); g.fillRect(0, 80, 240, 10); g.fillRect(240, 90, 60, 5); g.fillRect(240, 105, 60, 5); Color varvid[] = {Color.black, Color.green, Color.red, Color.blue, Color.pink, Color.yellow, Color.cyan, Color.orange,Color.black, Color.green}; int x[] = {10, 40, 70, 100, 130, 160, 190, 220, 250, 280}; int y[] = {10, 20 , 30, 40, 50, 60, 70, 80, 90, 90}; int p[] = {180, 160, 140, 120, 100, 80, 60, 40, 20, 20}; int klahvid[]={KeyEvent.VK_A}; String n[]= {"C", "D", "E", "F", "G", "A", "B", "C","D", "E"}; String q[]= {"Q", "W", "E", "R", "T", "Y", "U", "I","O", "P"}; String m[]= {"Do", "Re", "Mi", "Fa", "Sol", "La", "Si", "Do", "Re", "Mi"}; for(int u=0; u<10; u++){ g.setColor(varvid[u]); g.fillRect(x[u], y[u], 20, p[u]); g.setColor(Color.white); if((u==1)||(u==5)||(u==6)||(u==9)) { g.setColor(Color.black); } g.drawString((n[u]), x[u]+5 ,105); } for(int d=0; d<10; d++){ g.setColor(varvid[d]); g.fillRect(x[d], 290, 20, 20); g.setColor(Color.white); if((d==1)||(d==5)||(d==6)||(d==9)) { g.setColor(Color.black); } g.drawString((q[d]), x[d]+5 ,305); } g.setColor(Color.white); g.fillRect(10, 210, 300, 70 ); g.setColor(varvid[0]); for(int k=0; k<10; k++){ g.drawString((m[k]), x[k]+5, 270); } for(int h=226; h<251; h+=6){ g.drawLine(15, h, 300, h); } //class paint1(int q, int z){ //Graphics g=this.getGraphics(); // g.drawOval(q, z, 10, 10); // } g.setColor(varvid[3]); g.drawString("Miki tegi", 270, 332); addMouseListener(this); } public void mousePressed(MouseEvent e){ int valjus=65; //keskmine int x,y; x=(int)e.getX(); y=(int)e.getY(); for (int i=0; i<330; i+=20){ if((x>10+(i))&&(x<30+(i))&&(y>=10+(i/3))&&(y<=190-(i/3))){ try{ if((x>10)&&(x<30)){ korgus=57; } if((x>40)&&(x<60)){ korgus=59; } if((x>70)&&(x<90)){ korgus=61; } if((x>100)&&(x<120)){ korgus=62; } if((x>130)&&(x<150)){ korgus=64; } if((x>160)&&(x<180)){ korgus=66; } if((x>190)&&(x<210)){ korgus=68; } if((x>220)&&(x<240)){ korgus=69; } if((x>250)&&(x<270)){ korgus=71; } if((x>280)&&(x<330)){ korgus=73; } } catch(Exception ex){ ex.printStackTrace(); } kanal.noteOn(korgus, valjus); } } } public void mouseReleased(MouseEvent e){ kanal.noteOff(korgus); } public void mouseExited(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseClicked(MouseEvent e){} public boolean isFocusTraversable(){ return true; } public void keyPressed(KeyEvent e){ // System.out.println("hiir alla"); int kood=e.getKeyCode(); //if(all==kood)return; //all=kood; //class paint1(int q, int z){ // g.drawOval(q, z, 10, 10); //} Graphics t=this.getGraphics(); Graphics2D kaksD=(Graphics2D)t; kaksD.setColor(Color.red); try{ if (yles==true){ if(kood==KeyEvent.VK_Q){ yles=false; kaksD.fill(kujundid[0]); kaksD.drawLine(11, 256, 29, 256); kanal.noteOn(57,64); // if(all==kood)return; // all=kood; } } if (yles1==true){ if(kood==KeyEvent.VK_W){ yles1=false; kaksD.fill(kujundid[1]); kanal.noteOn(59,64); //if(all==kood)return; // all=kood; } } if(yles2==true){ if(kood==KeyEvent.VK_E){ yles2=false; kaksD.fill(kujundid[2]); kanal.noteOn(61,64); //if(all==kood)return; // all=kood; } } if(yles3==true){ if(kood==KeyEvent.VK_R){ yles3=false; kaksD.fill(kujundid[3]); kanal.noteOn(62,64); //if(all==kood)return; // all=kood; } } if(yles4==true){ if(kood==KeyEvent.VK_T){ yles4=false; kaksD.fill(kujundid[4]); kanal.noteOn(64,64); //if(all==kood)return; // all=kood; } } if(yles5==true){ if(kood==KeyEvent.VK_Y){ yles5=false; kaksD.fill(kujundid[5]); kanal.noteOn(66,64); //if(all==kood)return; // all=kood; } } if(yles6==true){ if(kood==KeyEvent.VK_U){ yles6=false; kaksD.fill(kujundid[6]); kanal.noteOn(68,64); //if(all==kood)return; // all=kood; } } if(yles7==true){ if(kood==KeyEvent.VK_I){ yles7=false; kaksD.fill(kujundid[7]); kanal.noteOn(69,64); //if(all==kood)return; // all=kood; } } if(yles8==true){ if(kood==KeyEvent.VK_O){ yles8=false; kaksD.fill(kujundid[8]); kanal.noteOn(71,64); //if(all==kood)return; // all=kood; } } if(yles9==true){ if(kood==KeyEvent.VK_P){ yles9=false; kaksD.fill(kujundid[9]); kanal.noteOn(73, 64); //if(all==kood)return; // all=kood; } } } catch (Exception s){} } public void keyReleased(KeyEvent e){ //System.out.println("hiir yles"); //all=0; Graphics t=this.getGraphics(); Graphics2D kaksD=(Graphics2D)t; Ellipse2D el=new Ellipse2D.Float(15,253, 12,6); Ellipse2D el1=new Ellipse2D.Float(45,250, 12,6); Ellipse2D el2=new Ellipse2D.Float(75,247, 12,6); Ellipse2D el3=new Ellipse2D.Float(105,244, 12,6); Ellipse2D el4=new Ellipse2D.Float(135,241, 12,6); Ellipse2D el5=new Ellipse2D.Float(165,238, 12,6); Ellipse2D el6=new Ellipse2D.Float(195,235, 12,6); Ellipse2D el7=new Ellipse2D.Float(225,232, 12,6); Ellipse2D el8=new Ellipse2D.Float(255,229, 12,6); Ellipse2D el9=new Ellipse2D.Float(275,226, 12,6); kaksD.setColor(Color.white); int kood=e.getKeyCode(); if(kood==KeyEvent.VK_Q){ kaksD.fill(el); kaksD.drawLine(11, 256, 29, 256); kanal.noteOff(57); yles=true; } if(kood==KeyEvent.VK_W){ kaksD.fill(el1); kaksD.setColor(Color.black); kaksD.drawLine(38, 250, 56, 250); kanal.noteOff(59); yles1=true; } if(kood==KeyEvent.VK_E){ kaksD.fill(el2); kaksD.setColor(Color.black); kaksD.drawLine(74, 250, 87, 250); kanal.noteOff(61); yles2=true; } if(kood==KeyEvent.VK_R){ kaksD.setColor(Color.white); kaksD.fill(el3); kaksD.setColor(Color.black); kaksD.drawLine(96, 244, 115, 244); kanal.noteOff(62); yles3=true; } if(kood==KeyEvent.VK_T){ kaksD.fill(el4); kaksD.setColor(Color.black); kaksD.drawLine(130, 244, 146, 244); kanal.noteOff(64); yles4=true; } if(kood==KeyEvent.VK_Y){ kaksD.fill(el5); kaksD.setColor(Color.black); kaksD.drawLine(160, 238, 176, 238); kanal.noteOff(66); yles5=true; } if(kood==KeyEvent.VK_U){ kaksD.fill(el6); kaksD.setColor(Color.black); kaksD.drawLine(189, 238, 209, 238); kanal.noteOff(68); yles6=true; } if(kood==KeyEvent.VK_I){ kaksD.fill(el7); kaksD.setColor(Color.black); kaksD.drawLine(220, 232, 235, 232); kanal.noteOff(69); yles7=true; } if(kood==KeyEvent.VK_O){ kaksD.fill(el8); kaksD.setColor(Color.black); kaksD.drawLine(250, 232, 267, 232); kanal.noteOff(71); yles8=true; } if(kood==KeyEvent.VK_P){ kaksD.fill(el9); kaksD.setColor(Color.black); kaksD.drawLine(273, 226, 295, 226); kanal.noteOff(73); yles9=true; } } public void keyTyped(KeyEvent e){} }