Here's a possible solution.
Create an
interface
(I only do this, as no not expose the mainJFrame
). Have theJFrame
form class implement it. It will only have one method,getNewUserButtont();
public interface GetButtonInterface { JButton getUserButton(); } public NewJFrame extends JFrame implements GetButtonInterface { private JButton newUserButton; @Override JButton getUserButton() { return newUserButton; } }
Then in your
JInternaFrame
class, it should take aGetButtonInterface
arg in the constructor. This is so you can get access to thenewUserButton
public AdminAddUser extends JInternalFrame { private JButton newUserButton; public AdminAddUser(GetButtonInterface gbi) { newUserButton = gbi.getUserButton(); } }
Now you can do what you want with that button. Every new
AdminAddUser
will use the same instance of thenewUserButton
. So you could 1. Use aInternalFrameListener
and overrideinternalFrameClosing()
to enable the button when the window is closed. 2. Use the button for thecancelButtonActionPerrfomed
public AdminAddUser extends JInternalFrame { private JButton newUserButton; public AdminAddUser(GetButtonInterface gbi) { newUserButton = gbi.getUserButton(); addInternalFrameListener(new InternalFrameAdapter(){ @Override public void internalFrameClosing(InternalFrameEvent e) { newUserButton.setEnabled(true); } }); } private void cancelButtonActionPerformed(ActionEvent e) { dispose(); newUserButton.setEnabled(true); } }
When you instantiate a new
AdminAddUser
use passNewJFrame.this
to it. Which is an instance ofGetButtonInterface
AdminAddUser addNew = new AdminAddUser(NewJFrame.this);