import java.applet.Applet; import java.awt.event.*; import java.awt.*; import javax.sound.midi.*; public class Pill extends Applet implements ActionListener, MouseListener{ TextField tf=new TextField("2"); int arv=Integer.parseInt(tf.getText().trim()); int laius=0; public Pill(){ add(tf); addMouseListener(this); tf.addActionListener(this); } public void paint(Graphics g){ int aukudearv=1; int x=60; g.setColor(Color.red); Polygon p=new Polygon(); p.addPoint(10, 80); p.addPoint(50, 100); p.addPoint(50, 60); g.fillPolygon(p); g.setColor(Color.white); g.fillRect(10, 60, 20, 40); g.setColor(Color.red); laius=(arv*40)+10; g.fillRect(50, 60, laius, 40); while(aukudearv<=arv){ g.setColor(Color.black); g.fillOval(0+x, 70, 20, 20); aukudearv++; x=x+40; } } public void mouseClicked(MouseEvent e){ int x=e.getX(); int y=e.getY(); System.out.println("hiirt vajutati"); try{ if ((x>=10 && x<=laius) && (y>=60 && y<=100)){ System.out.println("on ka arvutatud"); Synthesizer synthesizer=MidiSystem.getSynthesizer(); MidiChannel kanal=synthesizer.getChannels()[0]; //kanal 0; synthesizer.open(); int valjus=90; kanal.noteOn(60, valjus); Thread.sleep(500); kanal.noteOff(60); kanal.noteOn(62, valjus); Thread.sleep(500); kanal.noteOff(62); kanal.noteOn(64, valjus); Thread.sleep(500); kanal.noteOff(64); kanal.noteOn(65, valjus); Thread.sleep(500); kanal.noteOff(65); kanal.noteOn(67, valjus); Thread.sleep(500); kanal.noteOff(67); kanal.noteOn(69, valjus); Thread.sleep(500); kanal.noteOff(69); kanal.noteOn(71, valjus); Thread.sleep(500); kanal.noteOff(71); kanal.noteOn(72, valjus); Thread.sleep(500); kanal.noteOff(72); // System.exit(0); } }catch(Exception viga){ System.out.println(viga); } } public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mousePressed(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void actionPerformed(ActionEvent e){ arv=Integer.parseInt(tf.getText().trim()); repaint(); } public static void main(String argumendid[]){ Frame f=new Frame("Vilepill"); f.add(new Pill()); f.setSize(800, 400); f.setVisible(true); } }