![]() |
Help: GUI Connection 2
Help is available for each task, or you can go straight to the solution source code.
Now that you have built the GUI, you need to connect it to the kernel for your application. The kernel is the part of your application that does all the real work. Whenever you design an application, try to get as much separation between the GUI and kernel as possible. Think of the kernel as something that could possible be run standalone, taking arguments from the command line. You won't always be able to get that much separation, but it's a good goal and will make your design cleaner. For this Magercise, you will connect the GUI you created in GUI Conversion 2 to a stub kernel that is provided. If you were able to finish constructing the GUI, continue working in package magercises.gui2. If you were not able to finish, there is a GUI pre-built in package magercises.gui2a. This magercise will not go into as much help detail as GUI Connection 1. Make sure you have worked through that Magercise first. The functionality to implement will be as follows:
The rest of the menu options and Buttons should just bring up a dialog that says "option not yet available". This means that we need the following extra elements for our GUI:
No additional help for this task. Task 2Add the additional GUI elements that were mentioned in Task 1.
Create another dialog to get a string from the user. Do this the same way you created the number entry dialog for the GUI Connect 1 Magercise. Finally, we add a kernel object -- it's magercises.gui2a.solution this time. Task 3Connect the GUI based on the stated behavior.Lets take care of the easy ones first. We have several items whose only action at this point is to bring up one of the message dialogs we created. First, set up all the Help menu items and the Help button to bring up the "Abandon all help" dialog. For each of the following menu items and buttons, connect them to the "Option not yet avaiable" dialog in the same manner.
Now would be an opportune time to hide all connections and save the bean... All Drives CheckboxThis checkbox should have the effect of disabling all of the drive checkboxes. You do this by calling setEnabled(!allDrivesState) on each drive checkbox. The trick here is dealing with the "!" (not) part of the parameter. You need to provide a filter for the parameter to modify its value. We have provided a BoolOps class in the magercises.gui2a.solution package. It has a static method "not" that will return the boolean "not" of a boolean parameter passed in. Add a BoolOps variable to the design area. Because the method we need is static, the variable will provide us a convenient way to acces it; we don't need an actual object created for it. (Remember, Options->Add bean...") Connect the itemStateChanged event of the "All Drives" checkbox to the enabled property of the "A" checkbox. You'l need a parameter for this connection. Connect the value parameter of this connection to the not(b) method of the BoolOps variable you created. You'll need a parameter for this connection as well. Connect the b parameter of the not() connection to the state property of the "All drives" checkbox. Repeat this process for each of the drive letter checkboxes. This is a nice way to make it very clear that if all drives is checked, the individual drives don't apply. This is all we'll do with the checkboxes for this Magercise. Edit->Clear ListThis one's simple. Just connect the actionPerformed method of this menu item to the removeAll() method of the list. Selected->Open / Open ButtonTo perform this action, we need to call the kernel's openFile method passing the selected item in the list and the name of the editor to use.
Repeat the above steps for the Selected->Open menu item. Selected->CommandTo perform this action, we need to call the kernel's execute method passing the selected item in the list and the name of a command to execute.
Search ButtonThis command will call the kernel's search(list, file, text) method. (In real life this would probably also take state information about the drives that were checked, but we'll avoid that for this Magercise.) The search method takes a reference to the List so it can fill in the data. This is one of those places where sometimes you need to have abit more cohesion between the GUI and kernel. In general, this is not a good idea, and if we really worked at it, we could create a better separation by writing a method in the GUI that takes an array of Strings and adds them to the List, then changing search() to return just an array of Strings. ("Interested reader" time..) For now, we'll do it the direct way.
Dialog LocationsOnce again, the dialogs are coming up al over the place. Set their x,y constraint properties to 0,0. |
Copyright © 1996-1997 MageLang Institute. All Rights Reserved. |