import java.io.*; import java.applet.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.net.*; public class FastCode extends Applet implements KeyListener { String code = ""; String text = ""; int cur = 0; int shift = 0; int lines = 0; Graphics buf; Image mem; String line = ""; int x = 40, y = 60; Image bg = null; public void init() { try { String s = null; URL file = new URL(getCodeBase(), "FastCode.java"); DataInputStream dis = new DataInputStream(file.openStream()); while((s=dis.readLine()) != null) code += s+"\n#"; dis.close(); dis = null; } catch(IOException ioe) { ioe.printStackTrace(); } MediaTracker mt = new MediaTracker(this); bg = getImage(getCodeBase(), "bg.jpg"); mt.addImage(bg, 1); try { mt.waitForAll(); } catch(InterruptedException ie) { ie.printStackTrace(); } addKeyListener(this); mem = createImage(640, 480); buf = mem.getGraphics(); buf.drawImage(bg, 0, 0, this); repaint(); } public void paint(Graphics g) { update(g); } public void update(Graphics g) { g.drawImage(mem, 0, 0, this); } public void keyPressed(KeyEvent ke) { text += code.substring(cur, cur+1); y = 60+shift; x = 40; buf.drawImage(bg, 0, 0, this); StringTokenizer st = new StringTokenizer(text, "#"); lines = st.countTokens(); shift = (25-lines)*15; if(shift > 0) shift = 0; while(st.hasMoreTokens()) { line = st.nextToken(); x = 40; int ind = 0; while(line.substring(ind, ind+1).equals("\t") && ind < line.length() - 1) { x += 30; ind++; } if(y >= 60) { line = line.substring(ind); if(line.endsWith("\n")) line = line.substring(0, line.length()-1); buf.setColor(new Color(255, 235, 205)); buf.drawString(line, x, y); repaint(); } y += 15; } cur++; if(cur >= code.length()) { cur = 0; y += 45; } } public void keyReleased(KeyEvent ke) {} public void keyTyped(KeyEvent ke) {} }