亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? keyboard.java

?? Java模擬彈鋼琴程序
?? JAVA
字號:
// Keyboard.java
//Download:http://www.codefans.net
/*
 * Portions of Keyboard's source code were excerpted from Sun's MidiSynth.java 
 * source file. I've included Sun's original copyright and license, to be fair
 * to Sun.
 *
 * Copyright (c) 1999 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT
 * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
 * MODIFYING OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
 * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,
 * HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
 * THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or
 * in the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */

import java.awt.*;
import java.awt.event.*;
import java.util.Vector;

import javax.sound.midi.*;
import javax.swing.*;

/*
   This class creates a keyboard component that knows how to play a specific 
   instrument.
*/

public class Keyboard extends JPanel
{
   public final static Color KEY_BLUE = new Color (204, 204, 255);

   public final static int KEY_HEIGHT = 80, KEY_WIDTH = 16;

   private Key theKey;

   private MidiChannel channel;

   private Synthesizer synthesizer;

   private Vector blackKeys = new Vector ();
   private Vector keys = new Vector ();
   private Vector whiteKeys = new Vector ();

   public Keyboard ()
   {
      setLayout (new BorderLayout ());
      setPreferredSize (new Dimension (42*KEY_WIDTH+1, KEY_HEIGHT+1));

      int transpose = 24;  
      int [] whiteIDs = { 0, 2, 4, 5, 7, 9, 11 }; 

      for (int i = 0, x = 0; i < 6; i++) 
      {
           for (int j = 0; j < 7; j++, x += KEY_WIDTH) 
           {
                int keyNum = i * 12 + whiteIDs [j] + transpose;
                whiteKeys.add (new Key (x, 0, KEY_WIDTH, KEY_HEIGHT, keyNum));
           }
      }

      for (int i = 0, x = 0; i < 6; i++, x += KEY_WIDTH) 
      {
           int keyNum = i * 12 + transpose;

           blackKeys.add (new Key ((x += KEY_WIDTH)-4, 0, KEY_WIDTH/2,
                                   KEY_HEIGHT/2, keyNum+1));
           blackKeys.add (new Key ((x += KEY_WIDTH)-4, 0, KEY_WIDTH/2,
                                   KEY_HEIGHT/2, keyNum+3));
           x += KEY_WIDTH;

           blackKeys.add (new Key ((x += KEY_WIDTH)-4, 0, KEY_WIDTH/2,
                          KEY_HEIGHT/2, keyNum+6));
           blackKeys.add (new Key ((x += KEY_WIDTH)-4, 0, KEY_WIDTH/2,
                          KEY_HEIGHT/2, keyNum+8));
           blackKeys.add (new Key ((x += KEY_WIDTH)-4, 0, KEY_WIDTH/2,
                          KEY_HEIGHT/2, keyNum+10));
      }

      keys.addAll (blackKeys);
      keys.addAll (whiteKeys);

      addMouseListener (new MouseAdapter ()
                        {
                            public void mousePressed (MouseEvent e)
                            {
                               // Identify the key that was pressed. A null
                               // value indicates something other than a key
                               // was pressed.

                               theKey = getKey (e.getPoint ());

                               // If a key was pressed ...

                               if (theKey != null)
                               {
                                   // Tell key to start playing note.

                                   theKey.on ();

                                   // Update key's visual appearance.

                                   repaint ();
                               }
                            }

                            public void mouseReleased (MouseEvent e)
                            {
                               if (theKey != null)
                               {
                                   // Tell key to stop playing note.

                                   theKey.off ();

                                   // Update key's visual appearance.

                                   repaint ();
                               }
                            }

                            public void mouseExited (MouseEvent e) 
                            {
                               // This method is called if the mouse is moved
                               // off the keyboard component. If a key was
                               // pressed, we release that key.

                               if (theKey != null)
                               {
                                   // Tell key to stop playing note.

                                   theKey.off ();

                                   // Update key's visual appearance.

                                   repaint ();

                                   // The following assignment is needed so
                                   // that we don't execute the code within
                                   // mouseReleased()'s if statement should we
                                   // release a key after exiting the keyboard 
                                   // component. There is no need to tell the
                                   // key to stop playing a note after we have
                                   // already told it to do so. Furthermore,
                                   // we prevent an unnecessary repaint.

                                   theKey = null;
                               }
                            }

                            public Key getKey (Point point) 
                            {
                               // Identify the key that was clicked.

                               for (int i = 0; i < keys.size (); i++)
                               { 
                                    if (((Key) keys.get (i)).contains (point))
                                        return (Key) keys.get (i);
                               }

                               return null;
                            }
                        });
   }

   public boolean chooseInstrument (int instrumentID)
   {
      if (channel == null)
          return false;

      // Select new instrument based on ID.

      channel.programChange (instrumentID);

      return true;
   }

   public String [] getInstruments ()
   {
      if (synthesizer == null)
          return null;

      Instrument [] instruments = synthesizer.getLoadedInstruments ();

      String [] ins = new String [instruments.length];

      for (int i = 0; i < instruments.length; i++)
           ins [i] = instruments [i].toString ();

      return ins;
   }

   public void paint (Graphics g)
   {
      Graphics2D g2 = (Graphics2D) g;
      Dimension d = getSize ();

      g2.setBackground (getBackground ());
      g2.clearRect (0, 0, d.width, d.height);

      g2.setColor (Color.white);
      g2.fillRect (0, 0, 42*KEY_WIDTH, KEY_HEIGHT);

      for (int i = 0; i < whiteKeys.size (); i++)
      {
           Key key = (Key) whiteKeys.get (i);
           if (key.isNoteOn ()) 
           {
               g2.setColor (KEY_BLUE);
               g2.fill (key);
           }

           g2.setColor (Color.black);
           g2.draw (key);
      }

      for (int i = 0; i < blackKeys.size (); i++) 
      {
           Key key = (Key) blackKeys.get (i);
           if (key.isNoteOn ()) 
           {
               g2.setColor (KEY_BLUE);
               g2.fill (key);

               g2.setColor (Color.black);
               g2.draw (key);
           } 
           else 
           {
               g2.setColor (Color.black);
               g2.fill (key);
           }
      }
   }

   public void turnOff ()
   {
      if (synthesizer == null)
          return;

      // Attempt to unload all instruments.

      synthesizer.unloadAllInstruments (synthesizer.getDefaultSoundbank ());

      // Close the synthesizer, so that it can release any system resources
      // previously acquired during the open() call.

      synthesizer.close ();
      synthesizer = null;
   }

   public boolean turnOn ()
   {
      try
      {
          if (synthesizer == null) 
          {
              // Obtain the default synthesizer.

              if ((synthesizer = MidiSystem.getSynthesizer ()) == null)
                  return false;

              // Open the synthesizer, so that it can acquire any system
              // resources and become operational.

              synthesizer.open ();

          }
      }
      catch (Exception e)
      {
          e.printStackTrace();
          return false;
      }

      // Attempt load all instruments.

      synthesizer.loadAllInstruments (synthesizer.getDefaultSoundbank ());

      // Obtain the set of MIDI channels controlled by the synthesizer.

      MidiChannel [] midiChannels = synthesizer.getChannels ();

      // There must be at least one channel. Furthermore, we assume that the
      // first channel is used by the synthesizer. If you run into a problem,
      // use the index (other than 0) of the first non-null midiChannels
      // entry.

      if (midiChannels.length == 0 || midiChannels [0] == null)
      {
          synthesizer.close ();
          synthesizer = null;
          return false;
      }

      // Identify the channel to which note messages are sent.

      channel = midiChannels [0];

      return true;
   }

   /*
      This inner class describes an instrument key that knows how to start
      sounding and stop sounding its note. Furthermore, each key knows its
      size and location.
   */

   class Key extends Rectangle 
   {
      final static int ON = 0, OFF = 1, VELOCITY = 64;

      int kNum, noteState = OFF;

      public Key (int x, int y, int width, int height, int num) 
      {
         super (x, y, width, height);
         kNum = num;
      }

      public boolean isNoteOn () 
      {
          return noteState == ON;
      }

      public void off () 
      {
         setNoteState (OFF);
         //Keyboard.this.repaint ();

         // Send the key number to the channel so the note stops sounding.
         // Also send a keyup VELOCITY, which might affect how quickly the
         // note decays.

         if (channel != null)
             channel.noteOff (kNum, VELOCITY);
      }

      public void on () 
      {
         setNoteState (ON);
         //Keyboard.this.repaint ();

         // Send the key number (0 - 127, where 60 indicates Middle C) to the
         // channel so the note starts to sound. Also send a keydown VELOCITY,
         // which indicates the speed at which a key was pressed (the loudness
         // or volume of the note).

         if (channel != null)
             channel.noteOn (kNum, VELOCITY);
      }

      public void setNoteState (int state) 
      {
         noteState = state;
      }
   }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品国产欧美一区二区18| 精品久久久久久亚洲综合网| 视频一区视频二区中文| 777久久久精品| 日韩激情在线观看| 欧美成人一区二区三区| 丁香婷婷综合色啪| 中文字幕亚洲综合久久菠萝蜜| 99久久99久久精品国产片果冻| 中文字幕亚洲欧美在线不卡| 欧美三级三级三级爽爽爽| 日本vs亚洲vs韩国一区三区二区| 欧美一区二区三区四区在线观看 | 国精产品一区一区三区mba桃花| 欧美国产综合一区二区| 成人h版在线观看| 天天综合日日夜夜精品| 国产日韩成人精品| 欧美一区二区视频免费观看| 成人在线视频一区| 美女一区二区视频| 亚洲一区二区在线观看视频| 国产午夜精品美女毛片视频| 国产不卡在线播放| 久久成人免费日本黄色| 亚洲综合一区二区三区| 久久久久亚洲蜜桃| 欧美精品一区视频| 日韩欧美视频一区| 欧美酷刑日本凌虐凌虐| 欧美亚洲综合网| 91丨porny丨国产入口| 国产乱码精品一区二区三区五月婷| 亚洲综合久久久久| 亚洲欧美怡红院| 一区在线中文字幕| 国产精品久久久久永久免费观看| 最新国产成人在线观看| 国产欧美在线观看一区| 国产人妖乱国产精品人妖| 亚洲视频一区在线观看| 五月天中文字幕一区二区| 亚洲激情图片小说视频| 亚洲综合色视频| 国产一区二区三区| 国产一区二区在线看| 成人动漫视频在线| 欧美在线短视频| 久久影院视频免费| 亚洲欧美在线观看| 亚洲成人资源网| 国产精品一二三在| 日本系列欧美系列| 一区二区三区波多野结衣在线观看| 午夜久久电影网| 国产精品亚洲а∨天堂免在线| 国产精品一卡二卡在线观看| 91女人视频在线观看| 精品欧美乱码久久久久久| 亚洲精选视频在线| 精品一区二区三区在线视频| 99热这里都是精品| 国产欧美一区二区精品仙草咪| 亚洲444eee在线观看| 国产成人精品免费看| 日韩一区二区三区免费看 | 日韩欧美在线网站| 亚洲综合免费观看高清完整版在线| 国产一区二区看久久| 91福利国产精品| 国产欧美一区二区三区在线看蜜臀 | 久久人人超碰精品| 亚洲一区二区三区四区在线观看| 成人一级黄色片| 久久精品水蜜桃av综合天堂| 日韩电影一区二区三区| 99re66热这里只有精品3直播| 51精品视频一区二区三区| 日本一区二区成人| 高清在线不卡av| 中文字幕成人网| 国产成人一区二区精品非洲| 91.成人天堂一区| 中文字幕精品一区二区精品绿巨人| 中文一区二区完整视频在线观看| 久久一区二区三区国产精品| 国产日韩欧美高清在线| 亚洲色图一区二区三区| 东方欧美亚洲色图在线| 亚洲精品成人少妇| 色婷婷综合五月| 亚洲国产欧美在线| 精品视频资源站| 免费日本视频一区| 欧美不卡视频一区| 亚洲女人****多毛耸耸8| 国产99久久久国产精品| 亚洲高清不卡在线| 亚洲美女视频在线观看| 欧美三级电影精品| 奇米四色…亚洲| 中文字幕日韩一区| 国产区在线观看成人精品 | 亚洲成a人v欧美综合天堂| 日韩视频一区二区| 一本到一区二区三区| 激情欧美一区二区| 亚洲欧美中日韩| 精品日韩一区二区三区| 高清不卡一二三区| 久草中文综合在线| 有坂深雪av一区二区精品| 国产精品国产三级国产| 国产精品久久久久久妇女6080 | 欧美日韩一区二区三区在线看| 成人激情动漫在线观看| 福利一区福利二区| 日韩电影在线一区二区三区| 精品免费99久久| 欧美日韩高清不卡| 欧美日韩高清影院| 日韩一级高清毛片| 欧美精品免费视频| 99热精品国产| 国产精品18久久久久久vr| 美女高潮久久久| 极品美女销魂一区二区三区免费| 国产成人免费在线| 99视频在线观看一区三区| 国产在线精品国自产拍免费| 裸体歌舞表演一区二区| 日韩综合一区二区| 亚洲精品国产无天堂网2021| 六月丁香婷婷色狠狠久久| 国产成人av一区| 91免费版在线看| 欧美日韩国产精选| 欧美久久久久久蜜桃| 91亚洲资源网| 中文天堂在线一区| 日本aⅴ免费视频一区二区三区| 亚瑟在线精品视频| 日韩在线一区二区三区| 久久99热狠狠色一区二区| 婷婷成人激情在线网| 91啪九色porn原创视频在线观看| 日韩免费在线观看| 欧美日韩午夜影院| 国产亚洲人成网站| 亚洲一区二区欧美日韩| 秋霞午夜av一区二区三区| 欧美日韩国产另类一区| 亚洲综合一区二区| 国产剧情一区二区| 欧美亚洲综合在线| 国产片一区二区| 一区二区日韩av| 欧美性色综合网| 亚洲欧美影音先锋| 国产成人鲁色资源国产91色综| 5858s免费视频成人| 青青草国产成人av片免费| 在线成人av影院| 日韩中文字幕1| 欧美日韩免费视频| 亚洲视频免费观看| 在线看国产一区| 亚洲综合在线电影| 在线影院国内精品| 丝袜亚洲另类丝袜在线| 精品国产一区久久| 成人免费的视频| 欧美激情一区三区| 91蜜桃传媒精品久久久一区二区| 精品国精品自拍自在线| 日本二三区不卡| 韩国视频一区二区| 国产精品欧美综合在线| 丰满岳乱妇一区二区三区| 亚洲国产欧美一区二区三区丁香婷| 久久这里只有精品首页| 欧美性xxxxx极品少妇| 亚洲乱码日产精品bd| 国产成人福利片| 美女视频一区二区三区| 亚洲精品久久嫩草网站秘色| 欧洲生活片亚洲生活在线观看| 国产精品色噜噜| 欧美无砖砖区免费| 99久久er热在这里只有精品15 | 午夜视频一区在线观看| 中文字幕色av一区二区三区| 在线观看网站黄不卡| 蜜桃传媒麻豆第一区在线观看| 国产欧美一区二区在线| 2欧美一区二区三区在线观看视频| 欧美三级蜜桃2在线观看| 九九九久久久精品| 亚洲一级二级三级在线免费观看| 777色狠狠一区二区三区|