package edu.csusb.danby.applet;

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * DApplet extends JApplet by adding a DFrame, which produces an
 * external frame to run the applet in.
 * This code was developed from the GTSS project code
 *
 * @version    Wed Jul 24 07:59:31 PDT 2002
 */
public class DApplet extends JApplet implements DMenuAction, DControlPanelAction {
    protected DFrame dFrame;


    /**
     * public setter method for DFrame
     *
     * @param  frame  is the DFrame to be set
     */
    public void setDFrame(DFrame frame) {
        dFrame = frame;
    }



    /**
     * public accessor method for DFrame
     *
     * @return    The DFrame of the applet
     */
    public DFrame getDFrame() {
        return dFrame;
    }


    /**
     *  We include an  init() method
     *  as an example. In extending DApplet,
     *  set up the DFrame, related panels,
     *  and usually a model class which
     *  keeps the state of the applet.
     */
     public void init() {

        //main panel for applet
        SplashPanel panel = new SplashPanel("DApplet");

        //use single panel constructor
        dFrame = new DFrame("DApplet", panel);

        // construct controlPanel with reference to the applet
        String[] buttonLabel = {"Welcome", "to", "probstat"};
        DControlPanel controlPanel = new DControlPanel(dFrame, this, buttonLabel);

        panel.setBackground(Color.red);
        validate();
        // now we try to talk java into showing
        // things properly
        //panel.repaint();
        dFrame.pack();
        dFrame.show();
    }


    /**
     * paint method for applet
     * super.repaint() is called for frames and such
     */
    public void paint() {
        super.repaint();
    }


    /**
    * On destroying the applet, free up the resources for the JFrame.
    * Test for null value in case the frame was previously disposed.
    */
    public void destroy() {
        if (dFrame != null) {
            dFrame.dispose();
        }
    }


    /**
     * menuAction is called by DMenu. This is a no-op implementation,
     * the method should be over-ridden to be useful.
     *
     * @param  menuLabel      is the label of the menu
     * @param  menuItemLabel  is the label of the item
     * on the menu which was selected
     */
    public void menuAction(String menuLabel, String menuItemLabel) {
        ;
    }


    /**
     *  Null operator implementation of DMenuAction interface.
     *  Must be overridden to be useful!!
     *
     * @param  menuLabel      menuLabel called by action
     * @param  menuItemIndex  index of the item
     */
    public void menuAction(String menuLabel, int menuItemIndex) {
        ;
    }


    /**
     * controlPanelButtonAction is called by DControlPanel.
     * This no-op implementation should be over-ridden to be useful.
     *
     * @param  e            ActionEvent returned by the action
     */
    public void doControlPanelButtonAction(ActionEvent e) {
        ;
    }

}

