简体   繁体   中英

Enabling Jbutton in frame from another class - GUIBuilder

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.

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM