我正在尝试创建一个钢琴程序,在其中单击键,然后使用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();

    } 
}

===============>>#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=

  ask by user2288487 translate from so

未解决问题?本站智能推荐:

关注微信公众号