import java.awt.*; import java.applet.*; public class RunText3D extends Applet implements Runnable { private Image img; private Image offI; private Graphics offG; private Thread thread = null; private MediaTracker imageTracker; private int height,width; private String text; private int FontSize; private Font font; private boolean drawOK = false; public void init() { width = this.size().width; height = this.size().height; this.setBackground(Color.black); img = createImage(width,height); Graphics temp = img.getGraphics(); temp.setColor(Color.black); temp.fillRect(0,0,width,height); temp.setColor(Color.red); text = new String("Hello"); String s = new String(getParameter("Text")); if(s != null) text = s; FontSize = 30; font = new Font("TimesRoman",Font.BOLD,FontSize); temp.setFont(font); temp.drawString(text,10,height*3/4); imageTracker = new MediaTracker(this); imageTracker.addImage(img,0); try { imageTracker.waitForID(0); } catch(InterruptedException e){} offI = createImage(width,height); offG = offI.getGraphics(); } public void start() { if(thread == null) { thread = new Thread(this); thread.start(); } } public void run() { int x=15; int y = height-15; int R,G,B; offG.setFont(font); while(thread != null) { while(!drawOK) { R = (int)(255*Math.random()); G = (int)(255*Math.random()); B = (int)(255*Math.random()); try { thread.sleep(3000); } catch(InterruptedException ex){} offG.setColor(Color.yellow); offG.fillRect(0,0,width,height); repaint(); for(int i=0; i<10; i++) { offG.setColor(new Color((R+(255-R)*i/10),(G+(255-G)*i/10),(B+(255-B)*i/10))); offG.drawString(text,x+i,y-i); repaint(); try { thread.sleep(50); } catch(InterruptedException e){} } for(int i=0; i<10; i++) { offG.setColor(new Color((255-(255-R)*i/10),(255-(255-G)*i/10),(255-(255-B)*i/10))); offG.drawString(text,x+9,y-9); repaint(); try { thread.sleep(50); } catch(InterruptedException e){} } drawOK = true; repaint(); } } } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { int pX; g.drawImage(offI,0,0,this); pX = 0; while(drawOK) { g.drawImage(offI,pX,0,this); try { Thread.sleep(50); } catch(InterruptedException e){} pX+=3; System.out.println(pX); if(pX>width) { pX = 0; drawOK = false; } } } }