Have a scrolling status line(this howto is deprecated)Tag(s): DEPRECATED
/* ScrollStatus.java Optional parameters: message, width Default values: message = "Isn't scrolling text in the status line annoying? " width = 36 Example usage: <applet code="ScrollStatus.class" width=0 height=0> <param name="message" value="Hello World!"> <param name="width" value="24"> </applet> */ import java.util.*; import java.applet.Applet; public class ScrollStatus extends Applet implements Runnable { Thread thread; String message; StringBuffer buffer; int at; int width; public void init(){ message = getParameter("message"); if(message == null) message = " Isn't scrolling text in the status line annoying? "; String ws = getParameter("width"); if(ws == null) { width = 36; } else{ width = Integer.valueOf(ws).intValue(); } if(width < 5 || width > 180) { width = 36; } buffer = new StringBuffer(width); buffer.setLength(width); at = 0; if(message.length() < width) { char buf[] = new char[width]; for(int i = 0; i < width; ++i) { buf[i] = ' '; } message.getChars (0, message.length(), buf, (width - message.length()) / 2); message = new String(buf); } } public void start(){ thread = new Thread(this); thread.start(); } public void stop(){ thread.stop(); } public void scroll(){ int ml = message.length(); int k = at; for(int i = 0; i < width; ++i, ++k){ if(k >= ml) { k = 0; } buffer.setCharAt(i, message.charAt(k)); } getAppletContext().showStatus(buffer.toString()); at++; if(at >= ml) { at = 0; } } public void run(){ while(true){ scroll(); try{ Thread.sleep(25); // wait 25 ms } catch(InterruptedException e){ break; } } } }
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com