0

我正在尝试创建一个钢琴程序,您可以在其中单击键并使用 actionlistener 播放 jfugue 库中的音符。出于某种原因,单击大约 18 次后没有更改任何内容,按钮停止工作。我削减了代码来分析为什么会发生这种情况,因此只有两个注释。

提前感谢您的任何建议!

import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JComponent;
import java.awt.Color;
import javax.swing.JLayeredPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.*;
import org.jfugue.*; 

public class ChordPlayer2 extends JComponent{

public ChordPlayer2(){
    final Player player = new Player();

    JFrame frame = new JFrame();
    JButton  cButton, csharpButton;

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(null);
    buttonPanel.setLocation(0, 0);
    buttonPanel.setSize(1700, 1000);

    csharpButton = new JButton("");
    csharpButton.setLocation(100, 150);
    csharpButton.setSize(100,520);
    buttonPanel.add(csharpButton);

    cButton = new JButton("");
    cButton.setLocation(0, 150);
    cButton.setSize(160, 800);
    buttonPanel.add(cButton);



    class cClicker implements ActionListener {

        public void actionPerformed(ActionEvent event) {
            player.play("C");

            }
    }

    class csClicker implements ActionListener {  
    public void actionPerformed(ActionEvent event) {
            player.play("C#");
    }
    }


    ActionListener c = new cClicker();
    cButton.addActionListener(c);

    ActionListener cs = new csClicker();
    csharpButton.addActionListener(cs);


    buttonPanel.setOpaque(true);
    //return buttonPanel; 

    frame.add(buttonPanel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(1700, 1000);
    frame.setVisible(true);

}



public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    //JFrame.setDefaultLookAndFeelDecorated(true);
    ChordPlayer2 demo = new ChordPlayer2();

    } 
}
4

1 回答 1

1

这是 JFugue 中的一个已知错误:

https://code.google.com/p/jfugue/issues/detail?id=49

据称最新版本可以解决此问题:

https://code.google.com/p/jfugue/downloads/detail?name=jfugue-4.1.0-20120125.jar&can=2&q=

于 2013-04-29T23:48:08.600 回答