import java.awt.*; import java.applet.*; public class HelloWorld8 extends Applet implements Runnable { private int Width; private int Height; private String Str; private int StrLen; private Font f = new Font("Helvetica", Font.BOLD, 20); private FontMetrics fm; private Thread th; private int stp = 0; private double freq = 1.0; private boolean stpflg = false; public void init(){ String param; param = getParameter("strings"); Str = (param != null) ? param : new String("Hey! this is a test of ......."); param = getParameter("freq"); freq = (param != null) ? Double.valueOf(param).doubleValue() : 1.0; setBackground(new Color(255, 255, 255)); setForeground(new Color(255, 0, 0)); Width = size().width; Height = size().height; resize(Width, Height); } public void start() { if (th == null) { th = new Thread(this); th.start(); } } public void stop() { if (th != null) { th.stop(); th = null; } } public void run() { while (true) { if (++stp > Str.length()) stp = 0; repaint(); try { Thread.sleep(66); } catch (InterruptedException e){ } } } public void paint(Graphics g){ g.setFont(f); FontMetrics fm = g.getFontMetrics(); int x = (Width - fm.stringWidth(Str))/2; int yo = Height/2; double tmp; int y; for (int i = 0; i < Str.length(); i++) { tmp = Math.sin( freq * (double)(i + stp) / (double)Str.length() * Math.PI * 2.0); y = yo + (int)(tmp * yo * 0.5); g.drawChars(Str.toCharArray(), i, 1, x, y); x += fm.charWidth(Str.toCharArray()[i]); } } public boolean mouseDown ( Event e, int x, int y ) { if ( stpflg ) { th.resume(); stpflg = false; } else { th.suspend(); stpflg = true; } return true; } }