netbeans IDE: share event handler

I am new at using NetBeans and Java. I have created a keyboard inside a Jpannel using JtoggleButtons. The behavior for all of the buttons is very similar. Is there some way to have all the keys share an event handler? The code to pick to event handler is protected from modification by the netbeans IDE. When trying to use the IDE for this, each event gets an action listener and it's own event handler. I want them all to use the same event handler but I want to continue using the IDE tools.

W.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                // would like this to be:
                // handleKeyboardEvents(evt);
                WActionPerformed(evt);
            }

This what I'm having to do now:

// I would rather not use all these ActionPerformed functions
// and just have each action listener run handleKeyboardEvents.
    private void WActionPerformed(java.awt.event.ActionEvent evt) {
        handleKeyboardEvents(evt);
    }

    private void QActionPerformed(java.awt.event.ActionEvent evt) {
        handleKeyboardEvents(evt);
    }
    private void handleKeyboardEvents (java.awt.event.ActionEvent evt)
    {  
        javax.swing.JToggleButton keyClicked;
        keyClicked = (javax.swing.JToggleButton) evt.getSource();
        keyClicked.setEnabled(false);
    }
LVL 6
mgalig1010Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
I don't use Netbeans but can't you implement ActionListener in your main class and just choose 'this' in the IDE or something?
CEHJCommented:
(Or 'W' in your case)
mgalig1010Author Commented:
CEHJ,

Thanks for your reply.
I am trying not to go around the IDE on this. Currently the ActionListener is implemented in private void initComponents(). This code is managed by the IDE. Seems like it should be very simple but I can't figure out how to get the IDE to use my existing method when registering the ActionListener.

Regards,

Marcos
Mick BarryJava DeveloperCommented:
you can't get it to usae an existing method directly.
It needs to call actionPerformed() (whichg can then call an existing method)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
masnrockCommented:
Yeah... as far as I can think that's really about as good as it's going to be. I know it seems annoying as hell, but that's part of the fun that is Java.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.