📄 vscroller.java
字号:
/* Program : A vertical text scroller/* Title : Vscroller.java * Purpose : Web Text Display Applet * Author : Bill Boulton * Date : July 12, 1997 * Final Revision July 15 1997 * Version : 1.0 * email : boulton@amadeus.ccs.queensu.ca * Terms : Distribution of this source is being made in the hope that it may be found useful. It can be freely modified and redistributed provided this entire notice is left on the redistribution. * You'll notice that where code is used which was * modified from other source the authors are referenced * as a courtesy and in appreciation of their efforts * to promote "Public Domain" software and the understanding * of the Java Language.*/import java.applet.*;import java.awt.*;import java.util.*;import java.awt.image.*;public class vscroller extends Appletimplements Runnable{ int NumMessages=0 ; String Message[]; String Messages; /* get number of messages from tags */ int MaxLines; int Columns = 0; int NumLines = 0; char Screen[][]; /* array Maxlines Columns */ int YLinePos[]; int YLast[]; String FontColor; String ImageLoadMessage; int CursorX; int CursorY; int Index=0; int Xlimit=0,LoopCount=0; Thread Life=null; char DisplayMessage[]; String ScrollParam; boolean ScrollFlag = true; boolean set = false; String BackgroundImage; Image Tube; boolean ImageAvailable = false; boolean MsgDone = false; Color BackColor; String Bgcolor;/**************************/ /* */ /* Offscreen graphics *//* Variables *//* *//**************************/Image FinalScreen; Graphics osg; /**************************/ /* */ /* Screen graphics *//* Variables *//* *//**************************/Graphics g;/**************************//* Font Variables *//**************************/ Font Screen_Font; Font normalFont; FontMetrics fm; Color Screen_Font_Color; /* Parameter from html tag */ private int charWidth; private int charHeight; private int charDescent; private int NumChars; //The number of chars in the string private int NumSpaces; // The Number of spaces in the string private int LineFeed;/************************//* Screen Margins *//************************/ private int TopMargin; private int LeftMargin; private int RightMargin; private int BottomMargin; int offset;/************************//* Speed and distance *//* Variables from Parms *//************************/String Divider;int Divisor;String Pause;int Delay;/*****************************************//* Variables used to wrap the Messages *//* to which fit into the Display *//* area. *//*****************************************/ StringBuffer sb = new StringBuffer(); StringTokenizer st; String Line[]; public void init(){ BackgroundImage =getParameter("bgImage"); g=this.getGraphics(); if(getParameter("NumberMsg") != null) { Messages = getParameter("NumberMsg"); NumMessages = Integer.parseInt(Messages); } else NumMessages = 3; if(getParameter("Offset") != null) /* used to caclulate the yoffset */ { Divider = getParameter("Offset"); Divisor = Integer.parseInt(Divider); } else Divisor = 3; if(getParameter("TimeMs") != null) /* used to caclulate the yoffset */ { Pause = getParameter("TimeMS"); Delay = Integer.parseInt(Pause); } else Delay = 300; Message = new String[NumMessages]; Message[0] = getParameter("Msg0"); if (NumMessages > 1) Message[1] = getParameter("Msg1"); if (NumMessages > 2) Message[2]= getParameter("Msg2"); if (NumMessages > 3) Message[3]= getParameter("Msg3"); if (NumMessages > 4) Message[4]= getParameter("Msg4"); ImageLoadMessage="Loading Image"; resize(size().width, size().height); Screen_Font= initFont(); setFont(Screen_Font); fm = getFontMetrics(Screen_Font); if(fm != null) { charWidth = fm.charWidth(' '); charHeight = fm.getHeight(); charDescent = fm.getDescent(); } LineFeed = charHeight + 1; LeftMargin = 5; RightMargin = size().width - 5; TopMargin = 0; BottomMargin = size().height; CursorY = size().height; CursorX = LeftMargin; /*************************************************/ /* */ /* Find the Maximum Number of */ /* Characters that will fit into the */ /* Screen Area. */ /* This is used to define the number */ /* of rows and columns in the screen. */ /* */ /*************************************************/ for (LoopCount = 0; LoopCount < NumMessages-1;LoopCount++) FindMaxLength(Message[LoopCount]); YLinePos = new int[MaxLines]; initYpos(); /* Initialize the y position array */ g.setColor(Color.black); Screen = new char[MaxLines][Columns]; Init_Screen_Array(); /* MSIE 3.02 sets elements to null not good */ if (getParameter("Scroll") != null) { ScrollParam = getParameter("Scroll"); if(ScrollParam.equalsIgnoreCase("no")) ScrollFlag = false; } else ScrollFlag = true; if(getParameter("Colour") != null) { FontColor = getParameter("Colour"); Screen_Font_Color = Set_Color(FontColor); } else Screen_Font_Color = Color.yellow; if(getParameter("Bg") != null) { Bgcolor = getParameter("Bg"); BackColor = Set_Color(Bgcolor); } else BackColor = Color.black; setBackground(BackColor); FinalScreen = createImage(size().width,size().height ); osg = FinalScreen.getGraphics();} // end initpublic void initYpos(){ /*************************************************/ /* */ /* Set up the Line Y positions. */ /* These positions are used by the Insert */ /* Line routine to draw the Strings */ /* */ /*************************************************/ for (LoopCount = 0; LoopCount < MaxLines-1;LoopCount++) { if (LoopCount == 0) YLinePos[LoopCount] = size().height; else { YLinePos[LoopCount] = YLinePos[LoopCount - 1] + LineFeed ; } } // end for } // end initialize y positions/*********************************//* *//* The Following 2 routines load *//* the graphics images well *//* they are needed. *//* The initscreen also inits *//* the font and colour for the *//* offscreen graphics. *//* *//*********************************/public void initmain(){ if (!ImageAvailable) g.drawImage(Tube,0,0,size().width,size().height,this); else mainnoImage();}/*********************************//* The Following two routines *//* are used to set the background*//* to a solid color if no image *//* is provided. *//*********************************/ public void offsnoImage(){ osg.setColor(BackColor); osg.fillRect(0,0,size().width,size().height); osg.setColor (Screen_Font_Color);}public void mainnoImage(){ g.setColor(BackColor); g.fillRect(0,0,size().width,size().height); g.setColor (Screen_Font_Color);}public void initscreen(){ osg.setColor(Screen_Font_Color); osg.setFont(Screen_Font); if(!ImageAvailable) osg.drawImage(Tube,0,0,size().width,size().height,this); else offsnoImage();} /***********************************************//* *//* Microsoft Internet Explorer version 3.0 *//* initalizes the array with null characters. *//* As this causes some unpleasant results it *//* is necessary to initialize the screen array *//* with spaces... Hence the Init_Screen_Array()*//* routine. *//* *//***********************************************/public void Init_Screen_Array(){ int Lcount, Rcount = 0; char Temp; try { for(Lcount = 0; Lcount <=MaxLines;Lcount++) for(Rcount = 0; Rcount <=Columns - 1 ;Rcount++) { Temp = ' '; Screen[Lcount][Rcount] = Temp; } } catch (ArrayIndexOutOfBoundsException e){}} /* Screen array init ends *//********************************************************//* This routine was designed to return a color *//* for a given parameter. *//* The default color is green. This generic *//* module can be easily imported into any other *//* Progam. *//********************************************************/ public Color Set_Color(String Target){ if (Target.equalsIgnoreCase("black")) return( Color.black); else if (Target.equalsIgnoreCase("white")) return(Color.white); else if (Target.equalsIgnoreCase("gray")) return(Color.gray); else if (Target.equalsIgnoreCase("red")) return(Color.red); else if (Target.equalsIgnoreCase("green"))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -