import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.sound.midi.MidiChannel; import javax.sound.midi.MidiSystem; import javax.sound.midi.Synthesizer; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; @SuppressWarnings("serial") public class kolmkola2 extends JApplet implements MouseListener{ Synthesizer synt; MidiChannel kanal; int valjus=65; JButton nupp1 = new JButton(); JButton nupp2 = new JButton(); JButton nupp3 = new JButton(); JButton nupp4 = new JButton(); JButton nupp5 = new JButton(); JButton nupp12 = new JButton(); JButton nupp22 = new JButton(); JButton nupp32 = new JButton(); JButton nupp42 = new JButton(); JLabel label = new JLabel(); public kolmkola2(){ try{ synt=MidiSystem.getSynthesizer(); synt.open(); kanal=synt.getChannels()[0]; kanal.programChange(1,6); getContentPane().setLayout(null); nupp5 = new Joonenupp(77); nupp5.setBounds(20, 20, 100, 10); getContentPane().add(nupp5); nupp4 = new Joonenupp(74); nupp4.setBounds(20, 40, 100, 10); getContentPane().add(nupp4); nupp3 = new Joonenupp(71); nupp3.setBounds(20, 60, 100, 10); getContentPane().add(nupp3); nupp2 = new Joonenupp(67); nupp2.setBounds(20, 80, 100, 10); getContentPane().add(nupp2); nupp1 = new Joonenupp(64); nupp1.setBounds(20, 100, 100, 10); getContentPane().add(nupp1); nupp12 = new vahenupp(65); nupp12.setBounds(20, 90, 100, 10); getContentPane().add(nupp12); nupp22 = new vahenupp(69); nupp22.setBounds(20, 70, 100, 10); getContentPane().add(nupp22); nupp32 = new vahenupp(72); nupp32.setBounds(20, 50, 100, 10); getContentPane().add(nupp32); nupp42 = new vahenupp(76); nupp42.setBounds(20, 30, 100, 10); getContentPane().add(nupp42); nupp1.addMouseListener(this); nupp2.addMouseListener(this); nupp3.addMouseListener(this); nupp4.addMouseListener(this); nupp5.addMouseListener(this); nupp12.addMouseListener(this); nupp22.addMouseListener(this); nupp32.addMouseListener(this); nupp42.addMouseListener(this); label.setBounds(50, 120, 50, 20); getContentPane().add(label); } catch(Exception E){ E.printStackTrace(); } } public static void main(String[] arg) throws Exception{ JFrame f=new JFrame(); f.add(new kolmkola2()); f.setSize(600, 300); f.setVisible(true); } public void mangi(int algnoot){ kanal.noteOn(algnoot ,valjus); kanal.noteOn(algnoot+4 ,valjus); kanal.noteOn(algnoot+7 ,valjus); } public void mouseClicked(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mousePressed(MouseEvent e) { Object src = e.getSource(); if(src==nupp1 || src==nupp2 || src==nupp3 || src==nupp4 || src==nupp5){ Joonenupp nupp = (Joonenupp)e.getSource(); mangi(nupp.kysiPohitoon()); label.setText(MuusikaAbi.tahtnimi(nupp.kysiPohitoon())+" "+MuusikaAbi.tahtnimi(nupp.kysiPohitoon()+4)+" "+MuusikaAbi.tahtnimi(nupp.kysiPohitoon()+7)); } if(src==nupp12 || src==nupp22 || src==nupp32 || src==nupp42 ){ vahenupp nupp = (vahenupp)e.getSource(); mangi(nupp.kysiPohitoon()); label.setText(MuusikaAbi.tahtnimi(nupp.kysiPohitoon())+" "+MuusikaAbi.tahtnimi(nupp.kysiPohitoon()+4)+" "+MuusikaAbi.tahtnimi(nupp.kysiPohitoon()+7)); } } public void mouseReleased(MouseEvent e) { kanal.allNotesOff(); } }