home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Component;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
-
- public class Marquee extends Applet implements Runnable {
- Thread m_Marquee;
- String m_string = "";
- String m_font = "Courier";
- String m_style = "PLAIN";
- int m_size = 12;
- int m_fps = 10;
- final String PARAM_string = "string";
- final String PARAM_font = "font";
- final String PARAM_style = "style";
- final String PARAM_size = "size";
- final String PARAM_fps = "fps";
- private int m_nOffset;
- private int m_nMax;
- private int m_nMin;
-
- public void start() {
- if (this.m_Marquee == null) {
- this.m_Marquee = new Thread(this);
- this.m_Marquee.start();
- }
-
- }
-
- public String[][] getParameterInfo() {
- 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]"}, {"fps", "int", "Frame rate"}};
- return info;
- }
-
- public void stop() {
- if (this.m_Marquee != null) {
- this.m_Marquee.stop();
- this.m_Marquee = null;
- }
-
- }
-
- public void finalize() {
- }
-
- public String getAppletInfo() {
- return "Name: Marquee\r\n" + "Author: Stephen R. Davis\r\n" + "Created for Learn Java Now (c)";
- }
-
- public void run() {
- while(true) {
- int nSleepValue = 1000 / this.m_fps;
-
- try {
- ((Component)this).repaint();
- Thread.sleep((long)nSleepValue);
- } catch (InterruptedException var4) {
- this.stop();
- }
- }
- }
-
- public void destroy() {
- }
-
- public void init() {
- String param = ((Applet)this).getParameter("string");
- if (param != null) {
- this.m_string = param;
- }
-
- param = ((Applet)this).getParameter("font");
- if (param != null) {
- this.m_font = param;
- }
-
- param = ((Applet)this).getParameter("style");
- if (param != null) {
- this.m_style = param;
- }
-
- param = ((Applet)this).getParameter("size");
- if (param != null) {
- this.m_size = Integer.parseInt(param);
- }
-
- param = ((Applet)this).getParameter("fps");
- if (param != null) {
- this.m_fps = Integer.parseInt(param);
- }
-
- int nStyle = 0;
- if (this.m_style.equalsIgnoreCase("BOLD")) {
- nStyle = 1;
- }
-
- if (this.m_style.equalsIgnoreCase("ITALIC")) {
- nStyle = 2;
- }
-
- Font font = new Font(this.m_font, nStyle, this.m_size);
- ((Component)this).setFont(font);
- FontMetrics fm = ((Component)this).getFontMetrics(font);
- this.m_nMin = -fm.stringWidth(this.m_string);
- this.m_nMax = ((Component)this).size().width;
- this.m_nOffset = this.m_nMax;
- }
-
- public void paint(Graphics g) {
- int nVertOffset = ((Component)this).size().height;
- nVertOffset = (nVertOffset - this.m_size) / 2;
- g.drawString(this.m_string, this.m_nOffset, nVertOffset + this.m_size);
- this.m_nOffset += -1;
- if (this.m_nOffset < this.m_nMin) {
- this.m_nOffset = this.m_nMax;
- }
-
- }
- }
-