Hi,
the foll is the code:
class SalesReportStateCityWiseView extends JPanel implements Printable
{
SimpleDateFormat formatter = new SimpleDateFormat ("dd/MM/yyyy"

;
DecimalFormat numberformatter = new DecimalFormat("#0.00"

;
Font f;
FontMetrics fm;
int pageno;
String statename,fromdate,todate;
String[]companyinfo;
String[][]transinfo;
boolean print=false;
public SalesReportStateCityWiseView(int pageno,String statename, String[][]transinfo, String[]companyinfo, String fromdate,String todate)
{
//setSize(800,800);
this.pageno=pageno;
this.statename=statename;
this.transinfo=transinfo;
this.companyinfo=companyinfo;
this.fromdate=fromdate;
this.todate=todate;
setMinimumSize(new Dimension(900,3500));
setPreferredSize(new Dimension(900,3500));
}
public void paintBody(Graphics g){
f=new Font(null,Font.PLAIN,10);
g.setFont(f);
g.drawString ("Sales Analysis State/City Wise "+fromdate+" To "+todate,10,120);
//String acname=transactionhelper.getAcName(filerefno)[0];
g.drawString ("State Name : "+statename,10,135);
//f=new Font(null,Font.PLAIN,12);
//g.setFont(f);
fm = this.getFontMetrics(g.getFont());//get FontMatrics
g.drawLine(0,140,800,140);
g.drawString("City Name",10,155);
g.drawString("AMT.AFTER DIS.",160,155);
g.drawString("F.O.R.",310- fm.stringWidth("F.O.R"

,155);
g.drawString("NET SALE",380-fm.stringWidth("NET SALE"

,155);
g.drawLine(0,170,800,170);
int y=190;
int srno=1;
double amtafterdis=0;
double foramt=0;
double netsale=0;
// for (int i=((pageno*20)-20);i<transinfo.length ;i++ ){
for (int i=0;i<transinfo.length ;i++ ){
// if(i==(pageno*20))return;
g.drawString(transinfo
[6],10,y);
double amt=Double.parseDouble(transinfo[0]);
amt-=Double.parseDouble(transinfo[1]);
amt-=Double.parseDouble(transinfo[2]);
amt-=Double.parseDouble(transinfo[3]);
amt-=Double.parseDouble(transinfo[4]);
g.drawString(numberformatter.format(amt),220 - fm.stringWidth(numberformatter.format(amt)),y);
amtafterdis+=amt;
double famt=Double.parseDouble(transinfo[5]);
g.drawString(numberformatter.format(famt),320 - fm.stringWidth(numberformatter.format(famt)),y);
foramt+=famt;
g.drawString(numberformatter.format(amt-famt),380 - fm.stringWidth(numberformatter.format(amt-famt)),y);
netsale+=(amt-famt);
y=y+20;
}
g.drawLine(0,y,800,y);
g.drawString("Grand Total",10,y+20);
g.drawString(numberformatter.format(amtafterdis),220 - fm.stringWidth(numberformatter.format(amtafterdis)),y+20);
g.drawString(numberformatter.format(foramt),320 - fm.stringWidth(numberformatter.format(foramt)),y+20);
g.drawString(numberformatter.format(netsale),380 - fm.stringWidth(numberformatter.format(netsale)),y+20);
g.drawLine(0,y+30,800,y+30);
}//End paintBody
public void paint(Graphics g){
if(print){
((Graphics2D)g).scale(1,1);
}else{
((Graphics2D)g).scale(1.5,1.5);
}
Dimension d=getSize();
g.setColor(Color.white);
g.fillRect(0,0,(int)d.getWidth(),(int)d.getHeight());
g.setColor(Color.black);
paintBody(g);
PaintHeader.paintHeader(companyinfo,g);
//paintHeader(g);
//paintFooter(g);
}//end paint
//Add method print(Graphics g,PageFormat pageFormat,int pages)for printing
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
//setDoubleBuffered(false);
disableDoubleBuffering(this);
this.paint(g2d);
enableDoubleBuffering(this);
//setDoubleBuffered(true);
return(PAGE_EXISTS);
}//End print
public static void disableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(false);
}
/** Re-enables double buffering globally. */
public static void enableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(true);
}
}//end file
Please help.
Thanks