Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JButton

Status
Not open for further replies.

Markrp

Technical User
Nov 3, 2005
4
GB
I Have array of JButtons if a 8x8 grid I want to click a button and change the icon of another in the grid (not the one clicked), I dont seem to be able to access the array outside the mouse listener.

class test
{
//cant access this why?
private JButton but[] = new JButton[64];

private class MyMouseAdapter extends MouseAdapter
{

public void mouseClicked(MouseEvent event)
{
JButton button = (JButton)event.getSource(); // this gets the clicked button but
}
}
 
Because private members can only be accessed from the same class and the mouse adapter is a different class.

Try making it public.

Cheers,
Dian
 
Depending on your situation, I would also consider extending the AbstractAction class and setting the Action of your JButtons to your new AbstractAction. This will save you the trouble of having to store an array of 64 JButtons and manage it. Let each button be it's own object and handle it's own events.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top