troubleshooting Question

netbeans IDE: share event handler

Avatar of mgalig1010
mgalig1010 asked on
5 Comments2 Solutions749 ViewsLast Modified:
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);

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) {

    private void QActionPerformed(java.awt.event.ActionEvent evt) {
    private void handleKeyboardEvents (java.awt.event.ActionEvent evt)
        javax.swing.JToggleButton keyClicked;
        keyClicked = (javax.swing.JToggleButton) evt.getSource();
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros