Reputation: 9
I have a program that tests numbers if they are prime. I have a basic GUI that contains a textfield and a button called check. Now, I have extended this program by adding a simple GUI number keypad. On the original GUI, I added a new button called keyboard so when pressed, it will open the GUI number keypad and disable the check button. Now my question is how do I re-enable the check button if the GUI number keypad window has been closed? Below is a snippet of my code:
if (event.getSource()==jbKeyboard) {
jbCheck.setEnabled(false);
KeyboardGui g = new KeyboardGui();
if (g.equals(DISPOSE_ON_CLOSE)) {
jbCheck.setEnabled(true);
}
}
but this does not work.
Upvotes: 0
Views: 369
Reputation: 617
You add a WindowListener
for the keypad, and in the WindowClosing(WindowEvent e)
method, you can do your jbCheck.setEnabled(true);
Not sure what KeyboardGui, but something like this (added after you declare and initialize g):
g.addWindowListener(this);
Then you will need to implement WindowListener
and add the appropriate methods.
Here is the Java Tutorial on window Listeners: http://docs.oracle.com/javase/tutorial/uiswing/events/windowlistener.html
Upvotes: 2