home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-06-18 | 6.2 KB | 184 lines |
- //******************************************************************************
- // StaticMarquee.java: Applet
- //
- //******************************************************************************
- import java.applet.*;
- import java.awt.*;
-
- //==============================================================================
- // Main Class for applet StaticMarquee
- //
- //==============================================================================
- public class StaticMarquee extends Applet
- {
- // PARAMETER SUPPORT:
- // Parameters allow an HTML author to pass information to the applet;
- // the HTML author specifies them using the <PARAM> tag within the <APPLET>
- // tag. The following variables are used to store the values of the
- // parameters.
- //--------------------------------------------------------------------------
-
- // Members for applet parameters
- // <type> <MemberVar> = <Default Value>
- //--------------------------------------------------------------------------
- String m_string = "";
- String m_font = "Courier";
- String m_style = "PLAIN";
- int m_size = 12;
-
- // parameter names. to change the name of a parameter,
- // you need only make a single change. simply modify
- // the value of the parameter string below.
- //--------------------------------------------------------------------------
- final String PARAM_string = "string";
- final String PARAM_font = "font";
- final String PARAM_style = "style";
- final String PARAM_size = "size";
-
- // StaticMarquee Class Constructor
- //--------------------------------------------------------------------------
- public StaticMarquee()
- {
- // TODO: Add Constructor code here
- }
-
- // StaticMarquee Class Destructor
- //--------------------------------------------------------------------------
- public void finalize()
- {
- // TODO: Add Destructor code here
- }
-
- // APPLET INFO SUPPORT:
- // The getAppletInfo() method returns a string describing the applet's
- // author, copyright date, or miscellaneous information.
- //--------------------------------------------------------------------------
- public String getAppletInfo()
- {
- return "Name: StaticMarquee\r\n" +
- "Author: Stephen R. Davis\r\n" +
- "Created for Learn Java Now (c)";
- }
-
- // PARAMETER SUPPORT
- // The getParameterInfo() method returns an array of strings describing
- // the parameters understood by this applet.
- //
- // StaticMarquee Parameter Information:
- // { "Name", "Type", "Description" },
- //--------------------------------------------------------------------------
- public String[][] getParameterInfo()
- {
- String[][] info =
- {
- { PARAM_string, "String", "String to output in marquee" },
- { PARAM_font, "String", "Font to use" },
- { PARAM_style, "String", "PLAIN, BOLD, or ITALIC" },
- { PARAM_size, "int", "Font size [pts]" },
- };
- return info;
- }
-
- // The init() method is called by the AWT when an applet is first loaded or
- // reloaded. Override this method to perform whatever initialization your
- // applet needs, such as initializing data structures, loading images or
- // fonts, creating frame windows, setting the layout manager, or adding UI
- // components.
- //--------------------------------------------------------------------------
- public void init()
- {
- // PARAMETER SUPPORT
- // The following code retrieves the value of each parameter
- // specified with the <PARAM> tag and stores it in a member
- // variable.
- //----------------------------------------------------------------------
- String param;
-
- // string: String to output in marquee
- //----------------------------------------------------------------------
- param = getParameter(PARAM_string);
- if (param != null)
- m_string = param;
-
- // font: Font to use
- //----------------------------------------------------------------------
- param = getParameter(PARAM_font);
- if (param != null)
- m_font = param;
-
- // style: PLAIN, BOLD, or ITALIC
- //----------------------------------------------------------------------
- param = getParameter(PARAM_style);
- if (param != null)
- m_style = param;
-
- // size: Font size [pts]
- //----------------------------------------------------------------------
- param = getParameter(PARAM_size);
- if (param != null)
- m_size = Integer.parseInt(param);
-
- // resize(600, 80);
-
- // TODO: Place Addition Initialization code here
- // create the font here based on the parameters entered
- int nStyle = Font.PLAIN;
- if (m_style.equalsIgnoreCase("BOLD"))
- {
- nStyle = Font.BOLD;
- }
- if (m_style.equalsIgnoreCase("ITALIC"))
- {
- nStyle = Font.ITALIC;
- }
-
- Font font = new Font(m_font, nStyle, m_size);
-
- // now make this the font for this applet's window
- setFont(font);
-
- }
-
- // Place additional applet clean up code here. destroy() is called when
- // when you applet is terminating and being unloaded.
- //-------------------------------------------------------------------------
- public void destroy()
- {
- // TODO: Place applet cleanup code here
- }
-
- // StaticMarquee Paint Handler
- //--------------------------------------------------------------------------
- public void paint(Graphics g)
- {
- // nVertOffset is calculated to center the string
- // vertically in the window
- int nVertOffset = size().height;
- nVertOffset = (nVertOffset - m_size) / 2;
- g.drawString(m_string, 5, nVertOffset + m_size);
- }
-
- // The start() method is called when the page containing the applet
- // first appears on the screen. The AppletWizard's initial implementation
- // of this method starts execution of the applet's thread.
- //--------------------------------------------------------------------------
- public void start()
- {
- // TODO: Place additional applet Start code here
- }
-
- // The stop() method is called when the page containing the applet is
- // no longer on the screen. The AppletWizard's initial implementation of
- // this method stops execution of the applet's thread.
- //--------------------------------------------------------------------------
- public void stop()
- {
- }
-
-
-
-
- // TODO: Place additional applet Code here
-
- }
-