import java.awt.*; import java.awt.event.*; import javax.sound.midi.*; import java.io.*; public class ksysa extends Frame implements MouseListener, ActionListener{ protected Color x1=Color.yellow, x2=Color.yellow, x3=Color.yellow, x4=Color.yellow, x5=Color.yellow, x6=Color.yellow, x7=Color.yellow, x8=Color.yellow; Track track; Sequence sequence; Synthesizer synthesizer; MidiChannel kanal; Button alusta, salvesta, ava; boolean salvestada=false; int p; ShortMessage algus; ShortMessage kinni; ShortMessage lahti; //save TextArea failid=new TextArea(); Frame kysim=new Frame(); Button jah=new Button("Jah"); Button tyhista=new Button("Tühista"); TextField nimi=new TextField("Kirjuta siia faili nimi!"); //open TextArea failid2=new TextArea(); Frame kysim2=new Frame(); Button jah2=new Button("Jah"); Button tyhista2=new Button("Tühista"); TextField nimi2=new TextField("Kirjuta siia faili nimi!"); //error Frame error=new Frame(); Button errorjah=new Button("Salvesta ikka"); Button errorei=new Button("Tühista"); public ksysa(){ setSize(500, 300); setTitle("Midija"); addMouseListener(this); alusta=new Button("Alusta"); salvesta=new Button("Salvesta"); ava=new Button("Ava"); setLayout(new BorderLayout()); Panel paneel=new Panel(new GridLayout(1,3)); paneel.add(alusta); paneel.add(salvesta); paneel.add(ava); alusta.addActionListener(this); salvesta.addActionListener(this); ava.addActionListener(this); add(paneel, BorderLayout.SOUTH); setVisible(true); setResizable(false); addWindowListener(new aknakuular()); //save kysim.setSize(300,200); kysim.setTitle("Kas tahad salvestada?"); Panel savep=new Panel(new GridLayout(2,1)); Panel savep2=new Panel(new GridLayout(3,1)); savep2.setSize(300,90); jah.addActionListener(this); tyhista.addActionListener(this); savep2.add(nimi); savep2.add(jah); savep2.add(tyhista); savep.setLayout(new BorderLayout()); savep.add(savep2, BorderLayout.SOUTH); savep.add(failid); kysim.add(savep); kysim.setResizable(false); kysim.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ kysim.setVisible(false); } } ); //open kysim2.setSize(300,200); kysim2.setTitle("Kas tahad faili avada?"); Panel openp=new Panel(new GridLayout(2,1)); Panel openp2=new Panel(new GridLayout(3,1)); openp2.setSize(300,90); jah2.addActionListener(this); tyhista2.addActionListener(this); openp2.add(nimi2); openp2.add(jah2); openp2.add(tyhista2); openp.setLayout(new BorderLayout()); openp.add(openp2, BorderLayout.SOUTH); openp.add(failid2); kysim2.add(openp); kysim2.setResizable(false); kysim2.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ kysim2.setVisible(false); } } ); //error error.setSize(300,70); error.setTitle("Selline fail on juba olemas!!"); Panel errorp=new Panel(new GridLayout(2,1)); errorjah.addActionListener(this); errorei.addActionListener(this); errorp.add(errorjah); errorp.add(errorei); error.add(errorp); error.setResizable(false); error.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ error.setVisible(false); } } ); try{ synthesizer=MidiSystem.getSynthesizer(); synthesizer.open(); kanal=synthesizer.getChannels()[0]; }catch(Exception e){} } public void mousePressed(MouseEvent e){ try{ int x=e.getX(); int y=e.getY(); if(x>100 && x<130 && y>100 && y<200){ x1=Color.red; x2=Color.yellow; x3=Color.yellow; x4=Color.yellow; x5=Color.yellow; x6=Color.yellow; x7=Color.yellow; x8=Color.yellow; repaint(); new Piiksuja(kanal,60); lisapiiks(60); } if(x>135 && x<165 && y>100 && y<200){ x1=Color.yellow; x2=Color.red; x3=Color.yellow; x4=Color.yellow; x5=Color.yellow; x6=Color.yellow; x7=Color.yellow; x8=Color.yellow; repaint(); new Piiksuja(kanal, 62); lisapiiks(62); } if(x>170 && x<200 && y>100 && y<200){ x1=Color.yellow; x2=Color.yellow; x3=Color.red; x4=Color.yellow; x5=Color.yellow; x6=Color.yellow; x7=Color.yellow; x8=Color.yellow; repaint(); new Piiksuja(kanal, 64); lisapiiks(64); } if(x>205 && x<235 && y>100 && y<200){ x1=Color.yellow; x2=Color.yellow; x3=Color.yellow; x4=Color.red; x5=Color.yellow; x6=Color.yellow; x7=Color.yellow; x8=Color.yellow; repaint(); new Piiksuja(kanal, 65); lisapiiks(65); } if(x>240 && x<270 && y>100 && y<200){ x1=Color.yellow; x2=Color.yellow; x3=Color.yellow; x4=Color.yellow; x5=Color.red; x6=Color.yellow; x7=Color.yellow; x8=Color.yellow; repaint(); new Piiksuja(kanal, 67); lisapiiks(67); } if(x>275 && x<305 && y>100 && y<200){ x1=Color.yellow; x2=Color.yellow; x3=Color.yellow; x4=Color.yellow; x5=Color.yellow; x6=Color.red; x7=Color.yellow; x8=Color.yellow; repaint(); new Piiksuja(kanal, 69); lisapiiks(69); } if(x>310 && x<340 && y>100 && y<200){ x1=Color.yellow; x2=Color.yellow; x3=Color.yellow; x4=Color.yellow; x5=Color.yellow; x6=Color.yellow; x7=Color.red; x8=Color.yellow; repaint(); new Piiksuja(kanal,71); lisapiiks(71); } if(x>345 && x<375 && y>100 && y<200){ x1=Color.yellow; x2=Color.yellow; x3=Color.yellow; x4=Color.yellow; x5=Color.yellow; x6=Color.yellow; x7=Color.yellow; x8=Color.red; repaint(); new Piiksuja(kanal, 72); lisapiiks(72); } }catch(Exception viga ){} } public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void actionPerformed(ActionEvent e){ try{ String tulemus=""; File kataloog=new File("Lood"); if(!kataloog.isDirectory()){ kataloog.mkdir(); } String[] nimed=kataloog.list(); if(e.getSource()==alusta){ salvestada=true; ShortMessage algus = new ShortMessage(); algus.setMessage(ShortMessage.PROGRAM_CHANGE, 0, 16, 0); sequence=new Sequence(Sequence.PPQ, 4); track=sequence.createTrack(); track.add(new MidiEvent(algus, 0)); p=0; } //save if(e.getSource()==salvesta){ for(int i=0; i=0){ error.setVisible(true); } else{ salvestada=false; MidiSystem.write(sequence, 1, new FileOutputStream("Lood"+File.separator+fnimi+".mid")); } } catch(Exception viga){} kysim.setVisible(false); } if(e.getSource()==tyhista){ kysim.setVisible(false); } //open if(e.getSource()==ava){ for(int i=0; i