java - Action event on a JButton matrix -



java - Action event on a JButton matrix -

i can't handle event in matrix of jbuttons. need figure out button pressed, alter objects color match button.

i using code:

private class matrixbuttonlistener implements actionlistener { public void actionperformed(actionevent e) { jbutton btn = (jbutton) (e.getsource()); (int = 0; < matrixbouton.length; i++) { (int j = 0; j < matrixbouton[i].length; j++) { btn.equals(matrixbouton[i][j]); if (btn.getbackground() == color_neutral) { btn.setbackground(color_player); } } } } }

instead of looping through jbuttons trace button using evt.getsource(). homecoming reference actual button pressed. , can perform wish. can utilize next simplified code indeed:

private class matrixbuttonlistener implements actionlistener { public void actionperformed(actionevent e) { jbutton btn = (jbutton) (e.getsource()); if (btn.getbackground() == color_neutral) { btn.setbackground(color_player); } } }

java swing jbutton actionlistener

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -