import java.awt.*; public class myFont{ Graphics graphics; // Drawable canvas Image font; // The font-sheet Component comp; // Drawing component int SIZE=0; // SIZE of Image int CHARACTERS=16; // 16 characters on one line public myFont(Image fnt, int size, Component c){ font=fnt; SIZE=size; comp=c; } public void drawString(Image offscreen, String Text, int X, int Y, Color Background){ graphics=offscreen.getGraphics(); if(graphics!=null && Text != null && comp != null){ for(int i=0; i < Text.length(); i++){ char c=Text.charAt(i); // Calculate position in character-sheet int offset=((int)c)-32; int y=offset==0?0:offset/(CHARACTERS); int x=offset%(CHARACTERS); // Make image Image ch=comp.createImage(SIZE,SIZE); Graphics buffer=ch.getGraphics(); if(Background==null) buffer.setColor(new Color(0,60,0)); else buffer.setColor(Background); buffer.fillRect(0,0,SIZE,SIZE); buffer.drawImage(font, ( -(x*SIZE) ) , -(y*SIZE), comp); // Draw the character // works with too large space between char graphics.drawImage(ch, (X+(i*(SIZE))), Y, comp); graphics.drawImage(ch, (X+(i*(SIZE-1))), Y, comp); } }else{ System.out.println("font problem: Something has null (Text or Component)"); } } }