首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • 电子鼓程序,"Java Examples in Nutshell”中的例子,按键盘发声 [无满意答案结贴,结贴人:qingbt]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-07-13 08:25:47 楼主
    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( );
                    }
                });
        }
    }
    0  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-07-13 08:25:491楼 得分:0
    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【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 %                 
    楼主加油
    修改 删除 举报 引用 回复