public class ticker extends Applet implements Runnable {
-
/*=======================
-
o Variable Declarations o =======================*/
boolean isMoving; int xx; // text location int ntext; // number of text int text_width; // text width int width; // applet width int height; // applet height int delay; // time delay int fontsize; // size of font int selected; // selected caption
String[] s; // captions String[] url; // urls String[] target; // targets
Font font; // font face FontMetrics fm; // font metrics Thread runner; Color fgcolor, bgcolor, accolor, bdcolor;
Image offscrImg; // double buffer image Graphics offscr; // double buffer graphics
-
/*===========================
-
o Set Font and Color Method
public void setFont() {
-
String fontface = getParameter("fontface"); if (fontface == null)
-
fontface = "Times Roman";
String fontstyle = getParameter("fontstyle"); if (fontstyle == null || fontstyle.equals("plain"))
-
font = new Font(fontface, Font.PLAIN, fontsize);
-
font = new Font(fontface, Font.BOLD, fontsize);
-
font = new Font(fontface, Font.ITALIC, fontsize);
public void setColor() {
-
String c1 = getParameter("bgcolor"); String c2 = getParameter("fgcolor"); String c3 = getParameter("accolor"); String c4 = getParameter("bdcolor");
if (c1 == null) c1 = "255,255,255"; if (c2 == null) c2 = "000,000,000"; if (c3 == null) c3 = "255,000,000"; if (c4 == null) c4 = "150,150,150";
bgcolor = new Color(Integer.parseInt(c1.substring(0,3)),Integer.parseInt(c1.substring(4,7)), Integer.parseInt(c1.substring(8,11)));
fgcolor = new Color(Integer.parseInt(c2.substring(0,3)),Integer.parseInt(c2.substring(4,7)), Integer.parseInt(c2.substring(8,11)));
accolor = new Color(Integer.parseInt(c3.substring(0,3)),Integer.parseInt(c3.substring(4,7)), Integer.parseInt(c3.substring(8,11)));
bdcolor = new Color(Integer.parseInt(c4.substring(0,3)),Integer.parseInt(c4.substring(4,7)), Integer.parseInt(c4.substring(8,11)));
/*===================
-
o Initialize Method o ===================*/
-
isMoving = true; runner = new Thread(this); width = getSize().width; height = getSize().height; s = new String[MAX_SIZE]; url = new String[MAX_SIZE]; target = new String[MAX_SIZE];
offscrImg = createImage(width, height); offscr = offscrImg.getGraphics();
runner.start(); setFont(); setColor(); try { delay = Integer.parseInt(getParameter("delay")); } catch (Exception e) { delay = 10; }
String text; ntext = text_width = xx = 0; while ((text = getParameter("caption" + ntext)) != null) {
-
s[ntext] = text; url[ntext] = getParameter("url" + ntext); target[ntext] = getParameter("target" + ntext); if (target[ntext] == null)
-
target[ntext] = "_blank";
/*=========================
-
o Paint and Update Method o =========================*/
-
int c = 0; int i = xx; int h = (height + fontsize) / 2; selected = -1; boolean f = false;
while (s[c] != null && i < width) {
-
int w = fm.stringWidth(s[c]); offscr.setColor(fgcolor); offscr.drawString(s[c], i, h);
i += w + 20; if (++c >= ntext)
-
c = 0;
-
setCursor(HAND);
-
setCursor(DEFAULT);
if (isMoving)
-
xx--;
-
xx = 0;
-
}
-
paint(g);
/*===============
-
o Thread Method o ===============*/
-
while(true) {
-
try { runner.sleep(delay); } catch (Exception e) { } repaint();
}
