HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

What Is The AFC?
I know that football season is right around the corner, but you're not going to find an in-depth analysis of football's weaker conference here. The Application Foundation Classes, or AFC, are Microsoft's answer to the Abstract Windowing Toolkit (AWT). The AFC builds on the AWT foundation to provide more user-friendly controls for your applications. The AFC is currently available only as a preview release and requires a Java 1.02 or 1.1 compatible compiler and Virtual Machine.

Last month, I showed you how to obtain, install and use the latest Java SDK 2.0 from Visual J++. You'll need to get the Java SDK 2.0 to begin using the Application Foundations Classes. The Java SDK 2.0 currently is available in a preview release. Check out the Microsoft Java SDK Web site at http://www.microsoft.com/java for the latest information.

AFC Packages
The Application Foundation Classes are provided in three packages:

  • com.ms.ui: The User Interface package, which provides the primary framework for applets, applications and user interface controls. The User Interface package is what most people will be referring to when they speak of the AFC. It includes menus, buttons, canvases, edit controls, frames, lists, marquees, panels, radio buttons, scrollers and tree view controls.
  • com.ms.fx: The FX package provides advanced graphic controls in your applications including control over colors, fonts, curves, text and textures. The FX package provides more flexibility than AWT because it is not limited only to system-defined standards. Especially when developing Intranet applications, you can use the FX classes to use all of the fonts and colors available to your system.
  • com.ms.resource: The Resource package provides access to Win-32 resources, including dialog boxes and string tables, from your Java applications.
The User Interface package is the heart of the AFC. The focus here will be on how to begin to integrate the User Interface package into your own applications. I'll take a closer look at the FX and Resource packages in the near future.

AFC Hierarchy
The Application Foundation Classes are built on the foundation laid by the AWT. If you're already familiar with using the AWT, much of what you already know will remain familiar. Figure 1 illustrates the Application Foundation Class Hierarchy. The class names preceded by an asterisk (*) are AWT classes. As you can see, all of the Application Foundation Classes are extended from these base AWT classes. Figure 2 illustrates the class hierarchy of the user interface elements provided by the Application Foundation Classes. Many of these elements will be familiar to those familiar with AWT (i.e., button, check boxes, radio button) while others were not previously available (i.e., tree control, marquee).

Figure 1
Figure 1:

Figure 2
Figure 2:

AWT and AFC Compared
Before you think, "Here goes Microsoft again, trying to usurp yet another piece of the Java world", let's take a closer look. The Application Foundation Classes are built upon and extend the AWT, making it possible to mix both user interface models in your applications, which helps to preserve your user interface investment in your current applications and ease the transition over to a new programming model. Other user interface class models usually force a developer to choose between the AWT and another library.

Like the AWT, the Application Foundation Classes are written completely in Java, making them completely cross platform-independent. They provide new and better scroll bars and sliders, a tree control, a tab display, the ability to move through the user interface using just the keyboard and a file system explorer. The Application Foundation Classes permit the development of applications with user interfaces that are familiar to users of traditional Windows-based applications.

How To Use The AFC
Building Java applications with the Application Foundation Classes is no different from building your applications using the AWT. Instead of using the Applet and Frame classes, the UIApplet and UIFrame classes are substituted instead. Since the UIApplet and UIFrame classes are extended from the AWT Applet and Frame classes, it is possible to mix both AWT and Application Foundation Classes components. Listing 1 demonstrates how to create a shell AFC applet. Listing 2 demonstrates how to call the HTML necessary to call the shell applet. The AFC can also be used to create standalone applications. Listing 3 demonstrates how to create a standalone shell application using the Application Foundation Classes. Remember, you-ll need to have the Microsoft Java SDK 2.0 preview version installed and have your Visual J++ environment configured to use the pre-release version of the compiler. I described how to configure your Visual J++ environment to use the new version of the compiler in detail last month. In its current release, the Application Foundation Classes support both the traditional event handling model as used in these examples and the event delegation model supported by Java 1.1.

Availability
The Application Foundation Classes are available as part of the Microsoft Java SDK 2.0 on the Microsoft Java Web site, http://www.microsoft.com/java. If you're looking to use the Application Foundation Classes on non-Windows based platforms, the classes are also provided separately. Since the new compiler and the Application Foundation Classes are still pre-release versions, a few bugs still exist and they aren't optimized yet for full production use. The final version of the Application Foundation Classes is scheduled to ship with Internet Explorer Version 4.0 later this year.

Impressions
It's clear that the Application Foundation Classes will play an increasingly important role in the development of Java applications from a Microsoft perspective. It's uncertain if the Application Foundation Classes will win over the hearts and minds of all Java developers - given the current state of relations between Microsoft, Sun and JavaSoft. The Application Foundation Classes do provide a number of user interface elements that allow developers to create applications with familiar user interfaces (at least to Windows users). I'm sure that when the Application Foundation Classes and the Java SDK 2.0 are released in their final form, Microsoft will provide Visual J++ wizards which help to automate the process of creating applications and applets which use the Application Foundation Classes.

Microsoft currently does not plan on releasing the source code for the Application Foundation Classes. The plan is to make up for the lack of source code with documentation and support. This stance may hurt the Application Foundation Classes- chances of gaining wider acceptance; stay tuned though, this story is just beginning.

Next Month: Using Application Foundation Class User Interface Controls.

About the Author
John W. Fronckowiak is the author of "Teach Yourself Database Programming With Visual J++ In 21 Days" and "Teach Yourself OLE DB and ADO In 21 Days," Sams.net Publishing. Is there a special aspect of Visual J++ you would like to see discussed? Send your ideas and comments to John at [email protected]

	

Listing 1: How to create a shell AFC applet.

// Listing 1: A shell AFC applet. Use this as a template for building your own AFC applets.

import java.applet.*; 
import java.awt.*; 
import com.ms.ui.*; 
import com.ms.fx.*; 

public class AFCAppletShell extends UIApplet { 
  public init() { 
    setBackground(FXColor.gray);
    // Add other user interface components here
  } 
}

Listing 2: HTML required to embed the AFC Applet.

<HTML>
<TITLE>A Shell AFC Applet</TITLE>
<CENTER>An Example AFC Applet</CENTER>
<APPLET CODE=AFCAppletShell.class
        ID=AFCAppletShell
        WIDTH=200
        HEIGHT=200>
</APPLET>
</HTML>

Listing 3: How to create a shell AFC applet.

// Listing 3: A shell AFC application. Use this as a template 
// for building your own AFC applications.

import java.applet.*;
import java.awt.*;
import com.ms.ui.*;
import com.ms.fx.*;

public class AFCAppShell extends UIApplet
  public static void main(String args[])
    AFCShellFrame frame = new
      new AFCShellFrame("AFC Application Shell");
    frame.show();
    frame.resize(200,200);

    AFCAppShell applet = new AFCAppShell();

    // Add the applet to the frame
    frame.add(applet);

    applet.init();
  }

  public init() {
    setBackground(FXColor.gray);
    // Add other user interface components here
  }
}

class AFCShellFrame extends UIFrame {
  // Frame constructor
  public AFCShellFrame(String str) 
    super(str);
  }

  // Frame event handler
  public boolean handleEvent(Event evnt){
    switch(evnt.id) {
      // Close the application
      case Event.WINDOW_DESTROY:
       System.exit(0);
       return(true);
      // Pass all
other events to the UIFrame
      // event handler
      default:
       super.handleEvent(evnt);
    }
  }
}


}


 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.