/*
 *  =======================================================================
 *  DemoScrollPane.java : This applet displays an image inside a scrollpane,
 *  in this case, a label displaying an image downloaded from the server.
 *
 *  A scroll pane is used to display a child component with a built-in
 *  scrolling capability. Scroll bars in the horizontal and vertical 
 *  directions are automatically provided when the child compoent's size is
 *  too large to fit on the available viewport.
 *
 *  Adapted from : Pantham S., Pure JFC Swing, 1999.
 *  Modified by : Mark Austin                                   March, 2001
 *  =======================================================================
 */

import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.net.URL;

public class DemoScrollPane extends JApplet {

    URL codeBase;   // used for browser version only....
    URL sophieURL;  // URL for turtle image ...

    // 1. Create a scroll pane object and the other
    //    necessary objects.

    JScrollPane scrollPane = null;
    JLabel label = null;  // Not a canvas for JScrollPane!
    JPanel panel = null;  // supports double buffering
    Icon icon = null;

    public void init() {

        // 2. Get a handle on the JApplet's container.

        Container container = getContentPane();
        container.setLayout(new GridLayout(1,1));

        // 3. Download image icon from server and save ....

        codeBase = getCodeBase();
        try {
           sophieURL = new URL( codeBase, "images/sophie.gif");
        } catch ( java.net.MalformedURLException e ) {
           System.out.println("Badly specified URL!!");
        }

        ImageIcon icon = new ImageIcon( sophieURL );

        // 4. Create a Swing label and a panel for double buffering.

        label = new JLabel(icon);
        panel = new JPanel();
        panel.add(label);

        // 5. Create a scroll pane and add the panel to it.

        scrollPane = new JScrollPane(panel,
                     JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                     JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

        // 6. Add the scroll pane to the contentpane of JApplet.

        container.add(scrollPane);
    }
}
