Figure 1   TreeViewTest.java

/////////////////////////////////////////////////////////////////
//
// TreeViewTest.java
//

import wfc.ui.*;
import wfc.core.*;

/**
 * A test program for working with TreeView controls
 * @author Jonathan Locke
 */
public class TreeViewTest extends Form
{
    TreeView tv;

    /**
     * When the form is resized, resize the TreeView child
     * @param sender Ignored
     * @param e Ignored
     */
    public void onResize(Object sender, Event e)
    {
        tv.setSize(getClientSize());
    }

    /**
     * Constructor
     */
    public TreeViewTest()
    {
        // Create TreeView control
        tv = new TreeView();

        // Wire up resize handler
        addOnResize(new EventHandler(this.onResize));

        // Construct a small sample tree
        TreeNode root = new TreeNode("Root");
        TreeNode branch1 = new TreeNode("Branch 1");
        TreeNode branch1a = new TreeNode("1A");
        TreeNode branch1b = new TreeNode("1B");
        branch1.addNode(branch1a);
        branch1.addNode(branch1b);
        TreeNode branch2 = new TreeNode("Branch 2");
        TreeNode branch2a = new TreeNode("2A");
        TreeNode branch2b = new TreeNode("2B");
        branch2.addNode(branch2a);
        branch2.addNode(branch2b);
        root.addNode(branch1);
        root.addNode(branch2);
        tv.addNode(root);

        // Add the tree control to the form
        add(tv);

        // Set the form's title and show it as a dialog
        setText("TreeViewTest");
        showDialog();
    }

    /**
     * Main application entrypoint.
     * @param arg Command line arguments
     */
    static public void main(String[] arg)
    {
        new TreeViewTest();
    }
}

Figure 2   StaticImageTest.java

/////////////////////////////////////////////////////////////////
//
// StaticImageTest.java
//

import wfc.ui.*;

/**
 * Demonstrates how to load an image into a static image display control
 * @author Jonathan Locke
 */

public class StaticImageTest extends Form
{
    /**
     * Constructor
     */
    
    public StaticImageTest()
    {
        // Create static image control
        StaticImage si = new StaticImage();

        // Set bitmap
        si.setBitmap(new Bitmap("StaticImageTest.bmp"));

        // Add to form
        add(si);

        // Set title of form and show as a dialog
        setText("StaticImageTest");
        showDialog();
    }
    
    /**
     * Main application entrypoint.
     * @param arg Command line arguments
     */

    static public void main(String[] arg)
    {
        new StaticImageTest();
    }

}

Figure 4   ToolTipTest.java


 /////////////////////////////////////////////////////////////////
 //
 // ToolTipTest.java
 //
 
 import wfc.ui.*;
 
 /**
  * Demonstrate how easy it is to create tooltips in WFC
  * @author Jonathan Locke
  */
 
 public class ToolTipTest extends Form
 {
     /**
      * Constructor
      */
 
     public ToolTipTest()
     {
         // Create buttons and add to form
 
         Button b1 = new Button();
         b1.setText("Button1");
 
         Button b2 = new Button();
         b2.setText("Button2");
 
         add(b1);
         add(b2);
 
         // Move button B2 to the right of button B1
         Point pt = b1.getLocation();
         Point size = b1.getSize();
         b2.setLocation(pt.x + size.x, pt.y);
 
         // Create a tooltip control and set tooltips for the two button controls
         ToolTip tt = new ToolTip();
         tt.setToolTip(b1, "This is button number one");
         tt.setToolTip(b2, "This is button number two");
 
         // Set title of form and show as a dialog
         setText("ToolTipTest");
         showDialog();
     }
     
     /**
      * Main application entrypoint.
      * @param arg Command line arguments
      */
 
     static public void main(String[] arg)
     {
         new ToolTipTest();
     }
 }

Figure 5   MenuTest.java


 /////////////////////////////////////////////////////////////////
 //
 // MenuTest.java
 //
 
 import wfc.ui.*;
 import wfc.core.*;
 
 /**
  * A demonstration of how to use menus in WFC
  * @author Jonathan Locke
  */
 public class MenuTest extends Form
 {
     /**
      * Called when File/Exit menu item is clicked
      * @param sender Ignored
      * @param e Ignored
      */
     public void onFileExit(Object sender, Event e)
     {
         System.out.println("Exiting...");
         System.exit(0);
     }
 
     /**
      * Called when Help/About menu item is clicked
      * @param sender Ignored
      * @param e Ignored
      */
     public void onHelpAbout(Object sender, Event e)
     {
         System.out.println("About box goes here!");
     }
 
     /**
      * Constructor
      */
     public MenuTest()
     {
         // Create top-level menu items
         MenuItem miFile = new MenuItem();
         miFile.setText("&File");
         MenuItem miHelp = new MenuItem();
         miHelp.setText("&Help");
 
         // Add sub-menu items to top-level menu items
         MenuItem miExit = new MenuItem();
         miExit.setText("E&xit");
         MenuItem miAbout = new MenuItem();
         miAbout.setText("&About");
 
         // Wire up event handlers for exit and about menu items
         miExit.addOnClick(new EventHandler(this.onFileExit));
         miAbout.addOnClick(new EventHandler(this.onHelpAbout));
 
         // Add exit and about menus to file and help menus, respectively
         miFile.add(miExit);
         miHelp.add(miAbout);
 
         // Create main menu for application and add File and Help menus
         MainMenu m = new MainMenu();
         m.add(miFile);
         m.add(miHelp);
         setMenu(m);
 
         // Set the title of the form and show it as a dialog
         setText("MenuTest");
         showDialog();
     }
     
     /**
      * Main application entrypoint.
      * @param arg Command line arguments
      */
 
     static public void main(String[] arg)
     {
         new MenuTest();
     }
 }

Figure 6   ToolBarTest.java


 /////////////////////////////////////////////////////////////////
 //
 // ToolBarTest.java
 //
 
 import wfc.ui.*;
 import wfc.core.*;
 
 /**
  * Test of WFC toolbar support
  * @author Jonathan Locke
  */
 
 public class ToolBarTest extends Form
 {
     /**
      * Handles click events from button 1 of the toolbar
      * @param sender Ignored
      * @param e Ignored
      */
     public void onToolBarButton1Click(Object sender, Event e)
     {
         System.out.println("Button 1 clicked!");
     }
 
     /**
      * Handles click events from button 2 of the toolbar
      * @param sender Ignored
      * @param e Ignored
      */
 
     public void onToolBarButton2Click(Object sender, Event e)
     {
         System.out.println("Button 2 clicked!");
     }
 
     /**
      * Constructor
      */
 
     public ToolBarTest()
     {
         // Creates an image list with two images, one for each button
         ImageList il = new ImageList();
 
         il.addImage(new Bitmap("ToolBarButton1.bmp"));
         il.addImage(new Bitmap("ToolBarButton2.bmp"));
 
         // Create toolbar and set toolbar's image list
         ToolBar tb = new ToolBar();
         tb.setImageList(il);
 
         // Create toolbar button 1
         ToolBarButton tbb1 = new ToolBarButton();
         tbb1.setText("Button1");
         tbb1.setImageIndex(0);
         tbb1.setToolTipText("Button 1 here!");
 
         // Create toolbar button 2
         ToolBarButton tbb2 = new ToolBarButton();
         tbb2.setText("Button2");
         tbb2.setImageIndex(1);
         tbb1.setToolTipText("Button 2 here!");
 
         // Wire up event handlers
         tbb1.addOnClick(new EventHandler(this.onToolBarButton1Click));
         tbb2.addOnClick(new EventHandler(this.onToolBarButton2Click));
 
         // Add ToolBarButtons to ToolBar
         tb.addButton(tbb1);
         tb.addButton(tbb2);
 
         // Add toolbar to form
         add(tb);
 
         // Set title of form and show as a dialog
         setText("ToolBarTest");
         showDialog();
     }
     
     /**
      * Main application entrypoint.
      * @param arg Command line arguments
      */
 
     static public void main(String[] arg)
     {
         new ToolBarTest();
     }
 }

Figure 8   ListFonts.java


 /////////////////////////////////////////////////////////////////
 //
 // ListFonts.java
 //
 
 import wfc.ui.*;
 import java.util.*;
 
 /**
  * Lists available fonts 
  * @author Jonathan Locke
  */
 
 public class ListFonts
 {
     /**
      * Main application entrypoint.
      * @param arg Command line arguments
      */
 
     static public void main(String[] arg)
     {
         Graphics g = new Graphics(0);
         FontDescriptor fonts[] = g.getFontDescriptors(); 
         Hashtable h = new Hashtable();
 
         for (int i = 0; i < fonts.length; i++)
         {
             h.put(fonts[i].fullName, fonts[i].fullName);
         } 
 
         for (Enumeration e = h.keys(); e.hasMoreElements();)
         {
             String s = (String)h.get((String)e.nextElement());
             System.out.println(s);
         }
     }
 }