Dynamic behavior is added to a GUIKit user interface by executing Wolfram Language code. This lets one part of the definition interact with another, for example, specifying the behavior when a button is clicked or a menu choice is made.
This example shows both of the common cases of Script usage. There is a standalone Script block that defines the Wolfram Language function and Script blocks attached to events of the button to execute the function whenever the events are triggered.
You can create a working definition with just a button because the GUIKit framework has the convenient feature of automatically wrapping a definition with an appropriate window if the root widget of the definition is not already a window or frame, but is at least a widget that can be added to a window.
How can you learn the event names to use when attaching the scripts to the events of the button? If you have knowledge of the underlying Java event objects that are provided, you can determine the proper string name following Java naming conventions for the widget, or, if you interact with a running instance of the widget, you can query its list of valid names using the GUIInformation["widgetName"] function that works with GUIObject instances or within Script blocks.
This is just an alternate version that uses the fact that a no-argument GUIInformation or one dropping the first argument GUIObject can be called inside a Script block as well, since it inherits the contexted environment of the GUIObject it is running within.
If you have several different GUIs that all use the same script functionality, then you can place your code into a separate file and reference it from the Script definition with a ScriptSource option. This is discussed in the tutorials "Scoping" and "Deployment".