import javax.sound.sampled.*; import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.sound.midi.*; import javax.swing.*; public class kollid extends Applet implements ActionListener{ Button r_nupp=new Button("Rõõmus"); Button k_nupp=new Button("Kurb"); Panel p1 = new Panel(); Panel p2 = new Panel(); public kollid (){ r_nupp.addActionListener(this); k_nupp.addActionListener(this); p1.add(r_nupp); p2.add(k_nupp); add(p1); add(p2); } public void actionPerformed(ActionEvent e){ int r1 = (int)(Math.random()*100); int r2 = (int)(Math.random()*100); String kumb = e.getActionCommand(); if (kumb.equals("Rõõmus")){ try{ Synthesizer synthesizer=MidiSystem.getSynthesizer(); synthesizer.open(); MidiChannel kanal=synthesizer.getChannels()[0]; kanal.noteOn(r1, 120); kanal.noteOn(r2, 115); kanal.noteOn(90, 200); for(int korgus=1638; korgus>0; korgus-=500){ Thread.sleep(200); kanal.setPitchBend(korgus); } kanal.allNotesOff(); synthesizer.close(); }catch(Exception ex){ex.printStackTrace();} } if (kumb.equals("Kurb")){ int k1 = (int)(Math.random()*100); int k2 = (int)(Math.random()*100); try{ Synthesizer synthesizer=MidiSystem.getSynthesizer(); synthesizer.open(); MidiChannel kanal=synthesizer.getChannels()[0]; kanal.noteOn(k1, 30); kanal.noteOn(k2, 40); kanal.noteOn(40, 20); for(int korgus=2938; korgus>0; korgus-=500){ Thread.sleep(200); kanal.setPitchBend(korgus); } kanal.allNotesOff(); synthesizer.close(); }catch(Exception ex){ex.printStackTrace();} } } public static void main(String[] argumendid){ Frame f=new Frame("Kõllid"); kollid p=new kollid(); f.add(p); f.setSize(200, 100); f.setVisible(true); p.actionPerformed(null); } }