Results 1 to 3 of 3
  1. #1
    kiki2009 is offline Member
    Join Date
    Jun 2009
    Posts
    43
    Rep Power
    0

    Lightbulb Printer loop the same printing

    kindly help me. I try to print and the printer loop indefinite with the same printing without choosing to continue to print.
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.Toolkit.*;
    import javax.swing.border.*;
    import java.io.*;
    import java.awt.print.*;
    
    
    public class printer extends JFrame implements ActionListener , Printable {
    
    private JPanel jp;
    
    private JTextArea ta;
    
    private JButton PrintBtn, ExitBtn;
    
    public printer() 
    
    {
    
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); // centre the screen form
    
    setTitle("Computerize System"); 
    setSize(700,600);
    setLocationByPlatform(true); 
    setIconImage(new ImageIcon("logo/logo.jpg").getImage());
    
    setLocation((screen.width - 700)/2,((screen.height-600)/2));
    setResizable(false);
    setVisible(true);
    
    Container pane = getContentPane();
    
    JPanel jp = new JPanel();
    jp.setBorder(BorderFactory.createTitledBorder("")) ;
    jp.setBorder(BorderFactory.createBevelBorder(Bevel Border.RAISED));
    jp.setLayout(null);
    
    JTextArea ta = new JTextArea()
    {
    ImageIcon image = new ImageIcon( "Headline/headline.jpg" );
    
    public void paint( Graphics g ) {
    Dimension d = getSize();
    for( int x = 0; x < d.width; x += image.getIconWidth() )
    for( int y = 0; y < d.height; y += image.getIconHeight() ) 
    g.drawImage( image.getImage(), x, y, null, null );
    super.paint(g);
    }
    };
    
    ta.setBounds(42, 10, 600, 99); 
    ta.setOpaque(false);
    //ta.setLineWrap(true);
    //ta.setWrapStyleWord(true); 
    ta.setEditable(false);
    jp.add(ta); 
    pane.add(jp);
    
    PrintBtn = new JButton("Print");
    ExitBtn = new JButton ("Exit");
    
    jp.add(PrintBtn);
    PrintBtn.setBounds(100, 530, 100, 25);
    pane.add(jp);
    jp.add(PrintBtn);
    
    jp.add(ExitBtn);
    ExitBtn.setBounds(200, 530, 100, 25);
    pane.add(jp);
    jp.add(ExitBtn);
    
    PrintBtn.addActionListener(this);
    ExitBtn.addActionListener(this); 
    
    
    addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    }); 
    } 
    
    
    public void actionPerformed(ActionEvent event)
    {
    Object source = event.getSource();
    
    
    
    if (source == PrintBtn)
    {
    PrintBtn.setVisible(false);
    ExitBtn.setVisible(false);
    
    PrinterJob printJob = PrinterJob.getPrinterJob(); 
    printJob.setPrintable(this);
    
    if (printJob.printDialog()) {
    try {
    printJob.print(); 
    
    } catch (Exception PrintException) {
    PrintException.printStackTrace();
    }
    
    printJob.cancel(); 
    
    }
    
    printJob.cancel();
    PrintBtn.setVisible(true);
    ExitBtn.setVisible(true);
    
    }
    
    if (source == ExitBtn)
    {
    setVisible (false);
    dispose();
    
    }
    
    } 
    
    public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
    
    Graphics2D g2 = (Graphics2D) g;
    g2.translate(pf.getImageableX()+5, pf.getImageableY()+5); 
    Font f = new Font("Monospaced",Font.PLAIN,12);
    g2.setFont (f);
    paint (g2);
    
    return Printable.PAGE_EXISTS;
    }
    
    
    public static void main (String []args)
    { 
    printer pp = new printer();
    } 
    
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    Don't double post.
    printing a document A4 size paper

    db

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

Similar Threads

  1. printing to printer
    By ak88 in forum Advanced Java
    Replies: 3
    Last Post: 01-13-2013, 03:32 PM
  2. Printing in a printer
    By UJJAL DHAR in forum Advanced Java
    Replies: 5
    Last Post: 01-29-2011, 12:03 PM
  3. Printing Text using printer
    By UJJAL DHAR in forum New To Java
    Replies: 1
    Last Post: 12-06-2010, 04:26 PM
  4. Replies: 4
    Last Post: 09-10-2009, 01:40 PM
  5. printing simple text as text on printer
    By Nicholas Jordan in forum Advanced Java
    Replies: 0
    Last Post: 12-01-2008, 01:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •