Reputation: 99
I have created a JFrame using Netbeans IDE. I have disabled the submit button once it is pressed to process one action which i dealt in another class. If the action successfully completed i need to enable a button named Next in that frame and if it fails i need to enable Submit button again in that same frame. since they were private i cant access from other class. If i create object for that Jframe class button has not been enabled and i think entire frame has been called once again by Calling the function Initcomponents().
1) how to get enable the button in that frame after some action has been carried over in another class.
Upvotes: 0
Views: 816
Reputation: 347214
Normally, I normal provide a means by which the main form can register a ChangeListener
to the child form.
I then supply a method in the child form that returns a boolean
indicating that the required information has been filled or (ie isFormValid
)
When any particular part of the child form changes, it fires a change event, notifying the registered listeners that the child form has changed (in this case the parent form).
The parent form then checks the state of the child form and can make dissensions about what it should do...
This is the basic concept of an Observer Pattern, which is seen through out the Swing API.
It decouples you code and prevents unnecessary exposure of objects (you don't want the child form to have the ability to modify the parent form :P)
Upvotes: 1
Reputation: 6969
You need a way to access the buttons, or rather a method from your other class that will enable the buttons for you.
Or you can have a return value indicating success or failure and depending on that you can change the button status form the actionPerformed method.
Upvotes: 0