import java.applet.*; import java.awt.*; public class jumpball extends Applet implements Runnable{ Graphics g; FontMetrics FM; Color c; String words = "default"; Thread t; int width = 300, height = 200; int ballx = 0, bally = 0; int stringW, stringH; int point = 50, ball = 10; int delay = 300; int wordsL; char Carray[]; double decrement; public void init(){ width = getBounds().width; height = getBounds().height; g = getGraphics(); String parameter; parameter = getParameter("words"); if(parameter!=null) words = parameter; parameter = getParameter("delay"); if(parameter!=null) delay = Integer.parseInt(parameter); decrement = Math.PI/ 8; delay /= 8; wordsL = words.length(); Carray = new char[wordsL]; words.getChars(0,wordsL,Carray,0); Font font = new Font("TimesRoman", Font.BOLD,point); g.setFont(font); FM = g.getFontMetrics(); stringW = FM.stringWidth(words); stringH = FM.getHeight(); resize(stringW,stringH*2); } public void start(){ if(t == null) { t=new Thread(this); t.start(); } } public void run(){ int currentChar = 0; int x = 0; int oldX = 0; int charW = FM.charWidth(Carray[currentChar]); while(true){ try{ c = new Color((float)Math.random(),(float)Math.random(),(float)Math.random()); g.setColor(c); g.fillRect(0,0,width,height); g.setColor(Color.white); g.drawString(words,0,stringH+point); g.setColor(Color.black); int oldW = charW; charW = FM.charWidth(Carray[currentChar]); drawBall(c,oldX, x, oldW, charW); g.setColor(Color.black); g.drawChars(Carray, currentChar, 1, x, stringH + point); oldX = x; x+=charW; if(++currentChar == wordsL){ currentChar = 0; x = 0; } Thread.sleep(500); }catch (InterruptedException e){} } } public void paint(Graphics g){ g.setColor(Color.white); g.drawString(words,0,stringH+point); } void drawBall(Color c,int oldX, int x, int oldW, int charW){ if(x < oldX) return; int x1 = oldX + oldW / 2, x2 = x + charW / 2; int midX = (x1 + x2) / 2, midY = stringH; int radius = midX - x1; int y1; midX-=ball / 2; for(double r = Math.PI;r >= 0; r-= decrement){ try{ g.setColor(c); g.fillArc(ballx, bally, ball, ball, 0, 360); x1 = midX + (int)(Math.cos(r) * radius); y1 = midY - (int)(Math.sin(r) * radius); g.setColor(Color.yellow); g.fillArc(x1, y1, ball, ball, 0, 360); ballx = x1; bally = y1; Thread.sleep(delay); }catch (InterruptedException e){} } } }