Product Reviews
AFC- User Interface Controls
AFC- User Interface Controls
Aug. 1, 1997 12:00 AM
Foundations
This month I wrap up my two part review of the Application Foundation Classes with a closer look at the user interface controls it provides. In my past two columns, I've showed you how to install and use the Java SDK 2.0, which includes the Application Foundation Classes, and how to begin using the Application Foundation Classes in your own applications. Now it's time to take a closer look at what the Application Foundation Classes can do for the user interfaces of your Java applications.
The Controls
The Application Foundation Classes provide a number of enhanced user interface controls which can be used in your applications. These controls include:
Static controls - Used to display static text, graphic or both
Buttons - Used to create push buttons, radio buttons and check boxes
Lists - Used to create lists, combo boxes and dropdown combo boxes that contain text or graphics
Menus - Used to create floating menus, which can also include other buttons
Edit controls - Used to create single and multi-line edit controls
Status controls - Used to create status and progress bar controls
Tree controls - Used to create tree-like controls similar to those found in the Windows Explorer application
The Application Foundation Class user interface controls make it easy to mix and match different types of controls. It's very easy to mix text and graphics on many of the controls. Next, I review the more common user interface controls. I will show you how to create static controls, buttons and menus using the Application Foundation Classes. Note: For your reference, in the last Visual J++ Corner column I provided a complete hierarchy of the Application Foundation Classes, including all of the user interface classes.
Static Controls
There are three primary types of static controls in the Application Foundation Classes. They are the static text control, the static graphic control and the static item control (used to display both text and a graphic image). The static text control is represented by the UIText class, the static graphic control by the UIGraphic class and the static item control by the UIItem class. The UIText constructor takes a single parameter - the text to be displayed. The UIGraphic control also takes a single constructor parameter - an Image object which represents the image to be displayed. Finally, the UIItem control takes three important parameters - the text to display, an Image object representing the graphic to display and text alignment constants. Listing 1 presents a simple panel class that creates each of these static controls. Figure 1 illustrates how these controls are rendered.
Buttons
There are three primary types of button controls in the Application Foundation Classes. They are push button controls, radio button controls and check box controls. The push button control is represented by the UIPushButton class, the radio button control by the UIRadioButton class and the check box control by the UICheckButton class. The UIPushButton constructor takes two parameters - the text of the button and style of the button. You can create three button styles: using the UIPushButton.RAISED constant, you can create a standard push button; using the UIButton.TOGGLE constant, you can create a two-state button; using the UIButton.TRITOGGLE, you can create a three-state button. If you substitute a UIGraphic or UIItem object for the text parameter in the constructor, you can easily create a button that displays a graphic or text and a graphic. The UIRadioButton and UICheckButton constructors each take a single parameter - simply the text to display on the button. Listing 2 shows you how to create buttons using the Application Foundation Classes. Figure 2 illustrates how the buttons defined in Listing 2 are rendered.
Menus
Finally, the last Application Foundation Class I will review here is the Menu control. Menu controls are comprised of three main classes: UIMenuItem, which represents an actual menu item; UIMenuList, which represents a list of menu items; and UIMenuButton, which represents a menu push button. When a menu push button is pressed, the menu is displayed. Menus are pretty easy to put together. As outlined in Listing 3, you begin by creating a menu list. The UIMenuList.add method is called to add new menu items. You can add text strings to create simple text-based menu items or you can create complex menu items by adding different types. In the example in Listing 3, I have added a check box menu item by simply adding a UICheckButton object to the menu list and a graphic and text menu item by adding a UIItem object to the menu list. It's also easy to create sub-menus: just add another menu list to the main menu list. Once you have constructed your menu hierarchy, the UIMenuButton item is created, which marries a menu list with the menu button. Figure 3 illustrates the menu defined in Listing 3.
J/Direct and the Future of AFC
The Application Foundation Classes are certainly powerful. I've only touched the tip of the iceberg; the Application Foundation Classes also include a set of Enterprise Classes. The Application Foundation Enterprise Classes include the ability to build transaction-enabled applications in Java that interface with Microsoft Transaction Server and also provide access to legacy information systems and databases.
Microsoft has announced their J/Direct initiative, which will be part of the Java Virtual Machine in Internet Explorer Version 4.0. J/Direct should strike fear into the hearts of the pure Java camp, as it will allow Java applications written for the new Microsoft Java Virtual Machine to directly access the Windows API. Does this mean that developers will rush to create applications using the J/Direct interfaces? I prefer to wait and see. Even though this industry moves at faster than light speeds, sometimes it takes the future a lot longer to get here than you'd expect. It is my opinion though that some sort of marriage between the Application Foundation Classes and J/Direct is somewhere in the near future, with a set of Application Foundation Classes optimized for the Windows VM that utilize J/Direct and another portable set that doesn't. This could create a win-win situation for developers, since they could still develop portable applications, but rely on the speed and close integration with the Windows platform when running on the Java Virtual Machine. Will I be right? I don't know, but it's an interesting enough story to keep me tuned in every day.
Next Month: The Visual J++ Database Wizard: Is The Magic Right For You?
About John FronckowiakJohn Fronckowiak is the President of IDC Consulting, Inc., providing consulting and technical writing. He is also a Clinical Assistant Professor in Information Systems at the Adult Learning Program of Medaille College and is the author of several books and articles about iPhone development, programming, database design and development and networking. Fronckowiak has previously spoken at the Internet Commerce Expo in Boston, and the Conference on Instructional Technologies. In addition, he has over a decade of experience in the classroom as a college professor and runs dozens of training sessions for application developers.