-
-
Author : Bryan Harianto
-
Title : StringWalk.java
-
Date : November, 2001
-
-
Fields : 1. caption ( e.g. caption0 )
-
2. url ( e.g. URL0 )
-
3. target ( e.g. _self, _parent, _top, _blank, name )
-
4. delay ( e.g. 10 )
-
5. fontface ( e.g. TimesRoman )
-
6. fontstyle ( e.g. plain, bold, italic )
-
7. fontsize ( e.g. 12 )
-
8. bgcolor ( e.g. 255,255,255 )
-
9. fgcolor ( e.g. 000,000,000 )
-
10.accolor ( e.g. 255,000,000 )
-
11.bdcolor ( e.g. 150,150,150 )
-
-
===================================================================*/
import java.awt.*; import java.applet.*; import java.net.URL;
public class StringWalk extends Applet implements Runnable {
-
/*=======================
-
Variable Declarations
-
=======================*/
-
Set Font and Color Method
-
===========================*/
-
Initialize Method
-
===================*/
-
Paint and Update Method
-
=========================*/
-
Mouse Method
-
==============*/
-
Thread Method
-
===============*/
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 mouse_x; // mouse x coordinate int mouse_y; // mouse y coordinate 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
/*===========================
-
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)));
-
Integer.parseInt(c2.substring(4,7)), Integer.parseInt(c2.substring(8,11)));
-
Integer.parseInt(c3.substring(4,7)), Integer.parseInt(c3.substring(8,11)));
-
Integer.parseInt(c4.substring(4,7)), Integer.parseInt(c4.substring(8,11)));
/*===================
-
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";
setSize(width,height); offscr.setFont(font);
/*=========================
-
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); if (mouse_x >= i && mouse_x <= i + w
-
&& mouse_y <= h && mouse_y >= h - fontsize) {
-
offscr.setColor(accolor); offscr.drawLine(i, h + 2, i + w, h + 2); f = true; selected = c;
i += w + 20; if (++c >= ntext)
-
c = 0;
-
setCursor(HAND);
-
setCursor(DEFAULT);
if (isMoving)
-
xx--;
-
xx = 0;
public void update(Graphics g) {
-
paint(g);
/*==============
-
isMoving = false; return true;
public boolean mouseExit(Event evt, int x, int y) {
-
isMoving = true; mouse_x = -text_width; mouse_y = -text_width; return true;
public boolean mouseMove(Event evt, int x, int y) {
-
mouse_x = x; mouse_y = y; return true;
public boolean mouseUp(Event evt, int x, int y) {
-
if (selected != -1 && url[selected] != null) {
-
try {
-
getAppletContext().showDocument(new URL(url[selected]), target[selected]);
/*===============
-
while(true) {
-
try { runner.sleep(delay); } catch (Exception e) { } repaint();
}
HTML <html>
-
<applet code="StringWalk.class" width=500 height=25> <param name="delay" value="10">
<param name="fontface" value="Times Roman"> <param name="fontstyle" value="plain"> <param name="fontsize" value="12">
<param name="bgcolor" value="255,255,255"> <param name="fgcolor" value="000,000,000"> <param name="accolor" value="255,000,000"> <param name="bdcolor" value="150,150,150">
<param name="caption0" value="University of New South Wales"> <param name="url0" value="http://www.unsw.edu.au"> <param name="target0" value="_blank">
<param name="caption1" value="Computer Science and Engineering"> <param name="url1" value="http://www.cse.unsw.edu.au"> <param name="target1" value="_blank">
<param name="caption2" value="Software Engineering"> <param name="url2" value="http://www.cse.unsw.edu.au/seng"> <param name="target2" value="_blank">
</applet>
</html>
