import javax.sound.midi.*;
import java.awt.event.*;
import javax.swing.*;
public class Drums extends JFrame {
    MidiChannel channel;  // The channel we play on: 10 is for percussion
    int velocity = 64;    // Default volume is 50%    public static void main(String[  ] args) throws MidiUnavailableException
    {
        // We don't need a Sequencer in this example, since we send MIDI
        // events directly to the Synthesizer instead.
        Synthesizer synthesizer = MidiSystem.getSynthesizer( );
        synthesizer.open( );
        JFrame frame = new Drums(synthesizer);        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(50, 128);  // We use window width as volume control
        frame.setVisible(true);
    }        public Drums(Synthesizer synth) {
        super("Drums");        // Channel 10 is the GeneralMidi percussion channel.  In Java code, we
        // number channels from 0 and use channel 9 instead.
        channel = synth.getChannels( )[9];        addKeyListener(new KeyAdapter( ) {
                public void keyPressed(KeyEvent e) {
                    int key = e.getKeyCode( );
                    if (key >= 35 && key <= 81) {
                        channel.noteOn(key, velocity);
                    }
                }
                public void keyReleased(KeyEvent e) {
                    int key = e.getKeyCode( );
                    if (key >= 35 && key <= 81) channel.noteOff(key);
                }
            });        addMouseMotionListener(new MouseMotionAdapter( ) {
                public void mouseMoved(MouseEvent e) {
                    velocity = e.getX( );
                }
            });
    }
}

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【qingbt】截止到2008-07-13 08:25:48的历史汇总数据(不包括此帖):
    发帖的总数量:5                        发帖的总分数:100                      每贴平均分数:20                       
    回帖的总数量:45                       得分贴总数量:16                       回帖的得分率:35%                      
    结贴的总数量:3                        结贴的总分数:100                      
    无满意结贴数:1                        无满意结贴分:50                       
    未结的帖子数:2                        未结的总分数:0                        
    结贴的百分比:60.00 %               结分的百分比:100.00%                  
    无满意结贴率:33.33 %               无满意结分率:50.00 %                  
    楼主加油