int w1 = (int)k.getStringBounds("W",f).getWidth() + 1;
int w1 = (int)k.getStringBounds("W",f).getWidth();
   public int print (Graphics g, PageFormat pageFormat, int page) {      Graphics2D g2;      //--- Validate the page number, we only print the first page      if (page == 0) {         //--- Create a graphic2D object and set the default parameters         g2 = (Graphics2D) g;         g2.setColor (Color.black);         //--- Translate the origin to be (0,0)         g2.translate (pageFormat.getImageableX (), pageFormat.getImageableY ());         int w = (int)pageFormat.getImageableWidth() / numCols;     // proposed width         int h = (int)pageFormat.getImageableHeight() / numRows;     // proposed height         Font k = new Font("Courier New",Font.PLAIN,8);         LineMetrics l;         FontRenderContext f = null;         float j = 1;         for (; j < 36; j++) {            // derive the font and obtain the relevent information to compute            // the width and height            k = font.deriveFont(j);            f = new FontRenderContext(k.getTransform(),true,true);            l = k.getLineMetrics("Wy",f);            if (                  (w < (int)k.getStringBounds("W",f).getWidth() + 1) ||                     h < (int)(k.getStringBounds("g",f).getHeight() +                           l.getDescent() + l.getLeading())               )               break;         }         // since we were looking for an overrun of the width or height we need         // to adjust the font one down to get the last one that fit.         k = font.deriveFont(--j);         f = new FontRenderContext(k.getTransform(),true,true);         l = k.getLineMetrics("Wy",f);         // set the font of the print job         g2.setFont(k);         // get the width and height of the character bounds         int w1 = (int)k.getStringBounds("W",f).getWidth() + 1;         int h1 = (int)(k.getStringBounds("g",f).getHeight() +                     l.getDescent() + l.getLeading());         int x;         int y;         // loop through all the screen characters and print them out.         for (int m = 0;m < numRows; m++)            for (int i = 0; i < numCols; i++) {               x = w1 * i;               y = h1 * m;               // only draw printable characters (in this case >= ' ')               if (screen[getPos(m,i)].getChar() >= ' ' && !screen[getPos(m,i)].nonDisplay) {                  g2.drawChars(screen[getPos(m,i)].sChar, 0, 1,x , (int)(y + h1 - (l.getDescent() + l.getLeading())-2));               }               // if it is underlined then underline the character               if (screen[getPos(m,i)].underLine && !screen[getPos(m,i)].attributePlace)                  g.drawLine(x, (int)(y + (h1 - l.getLeading()-3)), (int)(x + w1), (int)(y + (h1 - l.getLeading())-3));            }         return (PAGE_EXISTS);      }      else         return (NO_SUCH_PAGE);   }