View Single Post
Eski 05/04/2007, 09:36   #3 (permalink)
aysila
Üye
 
aysila Adlı Üyenin Profil Grafiği
 
Üyelik Tarihi: 06/2005
Mesaj: 73
Varsayılan

Kodları kolaylık olsun diye sadeleştirdim. İstenirse komplede yollıyabilirim.

Bu ilgili nesneyi olusturdugum ana kod
Kod:
public class form_gor extends JFrame implements ActionListener{
    
  	.....
   yazdirici yazdir;
   PageFormat pageFormat;
   PrinterJob pj;
   
   public form_gor(Connection conn, int hedef, int ay){
      
	  ........
      yazdir=new yazdirici(conn, hedef, ay);
      //yazdir.setBounds(0,0,590,830);
      JScrollPane sp=new JScrollPane(yazdir);
      sp.setBounds(0, 0, 590, 500);
      add(sp);
      
      pj=PrinterJob.getPrinterJob();
      pageFormat=pj.defaultPage();
      Paper paper=pageFormat.getPaper();
      paper.setImageableArea(0,0, 590, 830);
      paper.setSize(590, 830);
      pageFormat.setPaper(paper);
      
   }
       
   ...........
   ...........
}
İlgili sınıfta budur:
Kod:
class yazdirici extends JComponent implements Printable{
    
   ..................
   ..................
    
   public yazdirici(Connection conn, int hedef, int ay){
       
       //this.setBounds(0, 0, 530, 860);
       this.setSize(590,830);
       //this.setAlignmentY(860);
       this.conn=conn;
       this.hedef_id=hedef;
       this.ay=ay;
       
      ...........................
    }
   
    
    public void paintComponent(Graphics g){
       g2=(Graphics2D) g;
       f=new Font("Arial", Font.PLAIN, 12);
       g2.setFont(f);
       
       if(fm==null){
           ust=(BufferedImage)createImage(590, 224);
           orta =(BufferedImage)createImage(590, 522);
           alt=(BufferedImage)createImage(590, 102);
           
           fm=g2.getFontMetrics();
           bl=fm.getAscent();
           fh=bl+ fm.getDescent();
           bosluk=fm.stringWidth(" ");
           for(int i=0; i<8;i++){
                satirlara_bol(text[i]);
           }
           ust_hazirla();
       }
       
       update(g2);
   }
    
   public void update(Graphics2D g){ 
           
       orta_hazirla();
       alt_hazirla();
       g.clearRect(0,0, 590, 830);
       g.setFont(f);
       g.drawImage( ust, 0,0, this);
       g.drawImage( orta, 0, 224, this);
       g.drawImage(alt, 0,746, this);
   }
   

   
  
   
   public int print(Graphics g, PageFormat pf, int pageIndex){
        if(pageIndex>=sayfaAdedi)
            return NO_SUCH_PAGE;
        ......................
        return PAGE_EXISTS;
   }
 
}
Teşekkür Ederim.
aysila hatta değil   Alıntı Yaparak Yanıtla