home *** CD-ROM | disk | FTP | other *** search
/ Learn Java Now / Learn_Java_Now_Microsoft_1996.iso / JavaNow / Code / Chap14 / StaticMarquee / StaticMarquee.class (.txt) next >
Encoding:
Java Class File  |  1996-07-29  |  2.7 KB  |  77 lines

  1. import java.applet.Applet;
  2. import java.awt.Component;
  3. import java.awt.Font;
  4. import java.awt.Graphics;
  5.  
  6. public class StaticMarquee extends Applet {
  7.    String m_string = "";
  8.    String m_font = "Courier";
  9.    String m_style = "PLAIN";
  10.    int m_size = 12;
  11.    final String PARAM_string = "string";
  12.    final String PARAM_font = "font";
  13.    final String PARAM_style = "style";
  14.    final String PARAM_size = "size";
  15.  
  16.    public void start() {
  17.    }
  18.  
  19.    public String[][] getParameterInfo() {
  20.       String[][] info = new String[][]{{"string", "String", "String to output in marquee"}, {"font", "String", "Font to use"}, {"style", "String", "PLAIN, BOLD, or ITALIC"}, {"size", "int", "Font size [pts]"}};
  21.       return info;
  22.    }
  23.  
  24.    public void stop() {
  25.    }
  26.  
  27.    public void finalize() {
  28.    }
  29.  
  30.    public String getAppletInfo() {
  31.       return "Name: StaticMarquee\r\n" + "Author: Stephen R. Davis\r\n" + "Created for Learn Java Now (c)";
  32.    }
  33.  
  34.    public void destroy() {
  35.    }
  36.  
  37.    public void init() {
  38.       String param = ((Applet)this).getParameter("string");
  39.       if (param != null) {
  40.          this.m_string = param;
  41.       }
  42.  
  43.       param = ((Applet)this).getParameter("font");
  44.       if (param != null) {
  45.          this.m_font = param;
  46.       }
  47.  
  48.       param = ((Applet)this).getParameter("style");
  49.       if (param != null) {
  50.          this.m_style = param;
  51.       }
  52.  
  53.       param = ((Applet)this).getParameter("size");
  54.       if (param != null) {
  55.          this.m_size = Integer.parseInt(param);
  56.       }
  57.  
  58.       int nStyle = 0;
  59.       if (this.m_style.equalsIgnoreCase("BOLD")) {
  60.          nStyle = 1;
  61.       }
  62.  
  63.       if (this.m_style.equalsIgnoreCase("ITALIC")) {
  64.          nStyle = 2;
  65.       }
  66.  
  67.       Font font = new Font(this.m_font, nStyle, this.m_size);
  68.       ((Component)this).setFont(font);
  69.    }
  70.  
  71.    public void paint(Graphics g) {
  72.       int nVertOffset = ((Component)this).size().height;
  73.       nVertOffset = (nVertOffset - this.m_size) / 2;
  74.       g.drawString(this.m_string, 5, nVertOffset + this.m_size);
  75.    }
  76. }
  77.