import javax.sound.midi.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.Vector; public class Noodirakend4 extends JApplet implements MouseListener{ JComboBox pank, pill; JButton nupp=new JButton("Mängi"); MidiChannel kanal; Synthesizer synt; public void init(){ try{ pank=new JComboBox(new String[]{"0", "1", "2", "3"}); pill=new JComboBox(); for(int i=0; i<128; i++){ pill.addItem(i+""); } Panel p1=new Panel(new GridLayout(2, 2)); p1.add(new JLabel("Pank:")); p1.add(pank); p1.add(new JLabel("Pill:")); p1.add(pill); getContentPane().add(p1); getContentPane().add(nupp, BorderLayout.SOUTH); nupp.addMouseListener(this); }catch(Exception e){e.printStackTrace();} } public void mousePressed(MouseEvent e){ try{ synt=MidiSystem.getSynthesizer(); synt.open(); kanal=synt.getChannels()[0]; //kanal 0; kanal.programChange(pank.getSelectedIndex(), pill.getSelectedIndex()); kanal.noteOn(60, 80); }catch(Exception ex){ ex.printStackTrace(); System.out.println(ex); } } public void mouseReleased(MouseEvent e){ kanal.noteOff(60); synt.close(); } public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} }