views:

77

answers:

2

Hi I have a java panel with 4 buttons. When I click on of these buttons, a new frame appears and the first is hidden with setVisibile(false). On that new window, I have another button, but when i click it, I got the event corresponding to the fourth button of the first window. Clicking the button again does the trick, but of course this is not acceptable. Am I missing something? I just show the frames with

nameOfTheFrame.setVisible(true);

and I have MouseListeners on every button.

The code of the last button is simply:

System.exit(0);

EDIT

Sample code:

    private void btn_joinGamePressed(java.awt.event.MouseEvent evt) {
            GraphicsTools.getInstance().getCreateGame().setVisible(false);
            GraphicsTools.getInstance().getMainPanel().setVisible(false);
            GraphicsTools.getInstance().getRegistration().setVisible(true);
}

GraphicsTools is a Singleton.

EDIT 2 Some more informations. I noticed that on MAC OS works fine. The problem happens only on Linux and Windows.

A: 

Try calling revalidate() on the frames as you change their viability.

Edit:

It could be something with the creation of the frames. Make sure you are calling 'pack()` on the frames.

Gordon
Tried, but nothing changed.
LucaB
+1  A: 

This must be happening because of your mouse listeners. May be it is identifying the old button in your first click which is in the same location of new button (It is just my guess).

Change the mouse listeners to action listeners. For a button, it is sufficient if you have action listener.

Try this.

RaviG
It works! Thanks a lot.
LucaB