Java Q&A
by Cliff Berg

Listing One
/* Copyright 1997 by Cliff Berg. */

public class BigCorporateApp
extends marimba.channel.ApplicationFrame
{
    public static final String[] allowedURLs =
    {
        "http://internal.ourcompany.com/OurMission",
        "http://internal.ourcompany.com/GrandeProject",
        "http://internal.ourcompany.com/SkunkworksProject"
    };
    public void start()
    {
        super.start();
        // Give the frame the ability to be closed
        addWindowListener
        (
            new java.awt.event.WindowAdapter()
            {
                public void windowClosing(java.awt.event.WindowEvent e)
                {

                   dispose();
                    getContext().stop();
                }
            }
        );
        setSize(600, 400);

        // Identify the file where user selections are saved between sessions
        String sep = "\";
        try { sep = 
             System.getProperty("file.separator"); } catch (Exception ex) {}
        selectionFileName = 
               getContext().getDataDirectory() + sep + "selection.txt";

        // Create a set of URL's for the user to choose from
        java.awt.Choice choice = new java.awt.Choice();
        for (int i = 0; i < allowedURLs.length; i++)
        {
            choice.addItem(allowedURLs[i]);
        }
        choice.addItemListener
        (
            new java.awt.event.ItemListener()
            {
                public void itemStateChanged(java.awt.event.ItemEvent e)
                {
                    String selection =
                                      allowedURLs[choice.getSelectedIndex()];
                    try
                    {
                        java.io.File f = new java.io.File(selectionFileName);
                        java.io.DataOutputStream dos = 
                                             new java.io.DataInputStream(f);
                        urlString = dos.writeUTF(selection);
                        dos.close();
                    }
                    catch (Exception ex)
                    {
                        // Could not save the selection!
                        ex.printStackTrace();
                    }

                    // Fetch and display the selected URL content
                    littleBrowserWindow.setDocumentString(urlString);
                }
            }
        );
        add("North", choice);
        // Instantiate the browser bean
        littleBrowserWindow = new sunw.hotjava.bean.HotJavaBrowserBean();
        add("Center", littleBrowserWindow);
        validate();
        // Display what choice user selected last time
        try
        {
            java.io.File f = new java.io.File(selectionFileName);
            java.io.DataInputStream dis = new java.io.DataInputStream(f);
            urlString = dis.readUTF();
            dis.close();
        }
        catch (Exception ex)
        {
            // File not found - display the first URL as a default
            urlString = allowedURLs[0];
        }
        littleBrowserWindow.setDocumentString(urlString);
    }
    public void stop()
    {
        dispose();
        littleBrowserWindow = null;
        super.stop();
    }
    private sunw.hotjava.bean.HotJavaBrowserBean littleBrowserWindow;
    private String urlString;
    private String selectionFileName;
}



1


