/************************************************************** END OF THE WORLD PRODUCTION COPYRIGHT (C) 1997, PARTICLE Permission to use & distribute for FREE if and only if some credit is given to Particle. I AM NOT RESPONSIBLE FOR ANYTHING -- Particle -- ***************************************************************/ import java.applet.*; import java.awt.*; import java.lang.*; import java.util.*; public class scroll extends Applet implements Runnable { /* thread support */ Thread myStringThread = null; /* out work place where we'll be drawing stuff */ private Graphics secondGraphics=null; /* imagine, to be associated with out workplace, (secondGraphics) */ private Image double_buffer=null; /* the message to be scrolled */ private String MyMessage=null; /* the font for the message */ private Font messageFont=null; /* the length of the message in pixels */ private int messageLength; /* the message current X, and Y position */ private int messageX,messageY; /* the speed with whitch the message scrolls */ private int messageSpeed; /* the width and height of the applet */ private int width,height; /* fontsize of the message in pixels */ private int fontsize; /* colors for foreground, background, and shadow (secondfgcolor).*/ Color bgcolor=null,fgcolor=null,secondfgcolor=null; /* The String name of the font to be used */ String myfont=null; /************************************************************** get some applet info ***************************************************************/ public String getAppletInfo(){ return (String)"Copyright (c) 1997, Particle"; } /************************************************************** get some applet parameter info ***************************************************************/ public String[][] getParameterInfo(){ String pinfo[][]= { {"string","String","The message to be scrolled"}, {"width","int","The width of virtual scrolling window"}, {"height","int","The height of virtual scrolling window"}, {"font","Font","The Font to be used"}, {"fontsize","int","The size of the font"}, {"fgcolor","000000 - FFFFFF","Color to be used for forground, (text)"}, {"shadowcolor","000000 - FFFFFF","Color to be used as shadow of text"}, {"bgcolor","000000 - FFFFFF","Color to be used for background"}, {"speed","int","The speed with whitch to scroll the message"}}; return pinfo; } /*************************************************************** Initialize the applet, get it ready to run. ****************************************************************/ public void init(){ /* temp String to help extract parameters */ String parameterGot = null; /* for what each parameter does, see the getParameterInfo() function */ if((MyMessage=getParameter("string"))==null) MyMessage="Use the \"string\" parameter to specify a string"; if((myfont=getParameter("font"))==null) myfont="Arial, Verdana, Helvetica"; if((parameterGot=getParameter("width"))==null) width = 400; else width = Integer.valueOf(parameterGot,10).intValue(); if((parameterGot=getParameter("height"))==null) height = 25; else height=Integer.valueOf(parameterGot,10).intValue(); if((parameterGot=getParameter("speed"))==null) messageSpeed = 2; else messageSpeed=Integer.valueOf(parameterGot,10).intValue(); if((parameterGot=getParameter("fgcolor"))==null) fgcolor = Color.black; else fgcolor=new Color(Integer.valueOf(parameterGot,16).intValue()); if((parameterGot=getParameter("bgcolor"))==null) bgcolor = Color.white; else bgcolor=new Color(Integer.valueOf(parameterGot,16).intValue()); if((parameterGot=getParameter("shadowcolor"))==null) secondfgcolor = Color.white; else secondfgcolor= new Color(Integer.valueOf(parameterGot,16).intValue()); if((parameterGot=getParameter("fontsize"))==null) fontsize = 20; else fontsize = Integer.parseInt(parameterGot); messageY=fontsize; /* resize it to exactly that size */ resize(width,height); /* create new font, of fontsize */ messageFont=new Font(myfont,Font.BOLD,fontsize); /* get the length of the message in pixels */ FontMetrics messageFontSize=getFontMetrics(messageFont); messageLength=messageFontSize.stringWidth(MyMessage); messageX=width; /* create an Image, and associated with out work place graphics object */ double_buffer = createImage(width,height); secondGraphics = double_buffer.getGraphics(); /* set the font in out work place graphics */ secondGraphics.setFont(messageFont); /* set the applet's foreground and background colors. we don't want it to flicker.. do we? */ setBackground(bgcolor); setForeground(fgcolor); } /****************************************************************** start the applet's thread *******************************************************************/ public void start(){ if (myStringThread == null){ //checks for previous instances... myStringThread = new Thread(this); myStringThread.start(); } } /****************************************************************** stop the thread *******************************************************************/ public void stop(){ if (myStringThread != null){ myStringThread.stop(); myStringThread = null; } } public void paint(Graphics g){ /* start by drawing out work place to the actual physical graphics screen */ g.drawImage(double_buffer,0,0,this); } /** * just call paint(Graphics); */ public void update(Graphics g){ paint(g); } /****************************************************************** the main function, it will "run" the applet * it is very important that this function is synchronized, otherwise, we could only run 1 applet at a time. * This function never releases the graphics of the applet. thus, it never flickers. (flickering is a bad thing). and because it's synchronized, we don't have to worry about releasing ... *******************************************************************/ public synchronized void run(){ /* do forever */ while(true){ /* move the message: right->left */ messageX-=messageSpeed; if ((messageX+messageLength) < 0) messageX = width; /* set background color of out work place */ secondGraphics.setColor(bgcolor); /* clear the current contents of out workplace */ secondGraphics.fillRect(0,0,messageLength+2,height); /* set the shadow color */ secondGraphics.setColor(secondfgcolor); /* draw the shadow */ secondGraphics.drawString(MyMessage,messageX+1,messageY); /* set the text color */ secondGraphics.setColor(fgcolor); /* draw the text, (will erase most of the shadow, but the shadow will still be visible by 1 pixel */ secondGraphics.drawString(MyMessage,messageX,messageY-1); repaint(); /* let time go by... */ try{ Thread.sleep(15); } /* if anything goes wrong, stop() the thread */ catch (InterruptedException e){ stop(); } } } } /*************************************************************************** END OF THE WORLD PRODUCTION COPYRIGHT (C) 1997, PARTICLE ****************************************************************************/