Painting the frame:
Public synchronized void paint (Graphics g){
int i,j;
int cx,cy;
char 1[] = new char[1];
Dimension d = sixe();
//draws the title on the frame
g.setFont(titleFont);
i=g.getFontMetrics().stringWidth(title);
g.drawString((title = =null)? "Spreadsheet":title,(d.width-i +(fontSize *3/2))/2,(fontSize *3/2));
//draws the input area on the frame g.setColor(inputColor);
g.fillRect(0,cellHeight, d.width, cellHeight);
g.setFont(titleFont);
for(i=0;i<rows+1;i ++)
{ cy=(i+2)*cellHeight;
g.draw3DRrect(0,cy,d.width,2,true);
if(I<rows) {
g.setColor(Color.blue);
g.drawString(""+(I+1),fontSize,cy+(fontSize * 3/2));
}
} g.setColor(Color.red);
for(i=0;I<columns;i++)
{ cx=i*cellWidth;
g.setColor(getBackgroung());
g.draw3DRect(cx + rowLabelWidth,2*cellHeight,1,d.height,true);
if(I<columns) { g.setColor(Color.red);
i0]=(char)((int)'A'+i);
g.drawString(new String(i),cx+rowLabelWidth+(cellWidth/2),d.height - 3);
}
}
for(i=0;i<rows;i++)
{for(j=0;i<columns;j++)
{ cx=(j*cellWidth)+2+rowLabelWidth;
cy=(i+1)*cellHeight)+2+titleHeight;
if(cells[I][j] != null) { cells[I][j].paint(g,cx,cy);
}
}
} g.setColor(getBackground());
g.draw3DRect(0,titleHeight,d.width,d.height-titleHeight,false);
inputArea.paint(g,1,titleHeight+1);
}
Whenever modifications occur in the applet, you have to repaint the applet's frame by using the repaint ( ) method of the applet class, you probably know that the repaint ( ) method calls the update ( ) method of the applet class if you recall earlier discussions on repainting the applet's frame, that in turn clarets a screen and calls the paint ( ) methods. A paint method then draws in the applet's frame. Clearing and after that drawing the frame produces a noticeable, flicker. For decrease it, commonly it's best to override the update ( ) method of the applet class. You do this through defining an update( ) method in your applet that does not clear the frame at all before painting it and, if possible clears only the parts of the screen which have changed. A Listing 20.9 displays the update ( ) method for the spreadsheet applet. That method uses a boolean value Called full update to determine whether to repaint the whole frame or only a portion of it. Whenever only a portion must be repainted, the suitable section is redrawn. The particle update occurs when the used selects a cell and the applet places the data related along with the cell in the input area and redraws the cell along with a white background. When the whole applet frame requires to be up dated, the update ( ) method calls the paint method directly without clearing the frame first.