import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.Applet; import javax.sound.midi.*; public class Akordion3 extends JApplet implements MouseListener{ JButton fNupp=new YmmarguneNupp("F"); JButton cNupp=new YmmarguneNupp("C"); JButton gNupp=new YmmarguneNupp("G"); Synthesizer synt; MidiChannel kanal; int valjus=100; public Akordion3(){ try{ synt=MidiSystem.getSynthesizer(); synt.open(); kanal=synt.getChannels()[0]; getContentPane().setLayout(null); fNupp.setBounds(10, 10, 30, 30); cNupp.setBounds(50, 10, 30, 30); gNupp.setBounds(90, 10, 30, 30); getContentPane().add(fNupp); getContentPane().add(cNupp); getContentPane().add(gNupp); fNupp.addMouseListener(this); cNupp.addMouseListener(this); gNupp.addMouseListener(this); } catch(Exception ex){ex.printStackTrace();} } public void mangiKolmkola(int algnoot){ kanal.noteOn(algnoot ,valjus); kanal.noteOn(algnoot+4 ,valjus); kanal.noteOn(algnoot+7 ,valjus); } public void mousePressed(MouseEvent e){ if(e.getSource()==fNupp){mangiKolmkola(65); } if(e.getSource()==cNupp){mangiKolmkola(60); } if(e.getSource()==gNupp){mangiKolmkola(67); } } public void mouseReleased(MouseEvent e){ kanal.allNotesOff(); } public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public static void main(String[] arg){ JFrame f=new JFrame(); f.add(new Akordion3()); f.setSize(300, 300); f.setVisible(true); } }