// simple number font drawer import java.awt.*; import java.applet.*; public class NumberFont extends Object { Image numbers[]; Applet applet; MediaTracker tracker; public NumberFont(Applet a, String dirName) { applet = a; tracker = new MediaTracker(a); // fetch the images numbers = new Image[10]; for (int i = 0; i < 10; i++) { numbers[i] = a.getImage(a.getCodeBase(), dirName + "/" + i + ".gif"); tracker.addImage(numbers[i], i); } try { tracker.waitForAll(); } catch (InterruptedException e) { } finally { if (tracker.isErrorAny()) System.out.println("Error while loading images"); } } public int drawString(Graphics g, String s, int x, int y) { int kern = x; int length = s.length(); for (int i = 0; i < length; i++) { Image glyph = numbers[s.charAt(i) - '0']; g.drawImage(glyph, kern, y, applet); kern += glyph.getWidth(applet); } return kern; } }