javano.java

来自「如果你想在自己的计算机游戏中创建音乐编辑器」· Java 代码 · 共 54 行

JAVA
54
字号
// Javano.java

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class Javano extends JApplet
{
   Keyboard keyboard;
   JComboBox instruments;

   public void init ()
   {
      JPanel panel = new JPanel ();
      panel.add (new JLabel ("Instruments:"));

      instruments = new JComboBox ();
      panel.add (instruments);

      getContentPane ().add (panel, BorderLayout.NORTH);

      keyboard = new Keyboard ();

      getContentPane ().add (keyboard, BorderLayout.SOUTH);
   }

   public void start ()
   {
      keyboard.turnOn ();

      DefaultComboBoxModel dcbm;
      dcbm = new DefaultComboBoxModel (keyboard.getInstruments ());
      instruments.setModel (dcbm);

      ActionListener al;
      al = new ActionListener ()
           {
               public void actionPerformed (ActionEvent e)
               {
                  JComboBox cb = (JComboBox) e.getSource ();

                  keyboard.chooseInstrument (cb.getSelectedIndex ());
               }
           };
      instruments.addActionListener (al);
   }

   public void stop ()
   {
      keyboard.turnOff ();
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?