0

I am trying to create a piano program where you click the key and using an actionlistener is plays the note from the jfugue library. For some reason after about 18 clicks without changing anything the buttons stop working. I cut down the code to analyze why this might happen, thus only two notes.

Thanks in advance for any advice!

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();

    } 
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    This code works fine for me, the buttons never stopped working. – syb0rg Apr 16 '13 at 23:32
  • Does the cut-down version stop in the same fashion? Do you have any output to look at, e.g., a console for a stacktrace to appear; if not, get that arranged, if so, what does it say? – arcy Apr 17 '13 at 00:18

1 Answers1

1

This is a known bug in JFugue:

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

The most recent version is claimed to fix this:

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

granmoe
  • 312
  • 1
  • 11