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

    Question printing a document A4 size paper

    i'm new to this printing a document A4 size paper, kindly help me.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

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

    Exclamation 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.

    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();
    }

    }
    Last edited by kiki2009; 04-29-2011 at 08:28 AM.

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

Similar Threads

  1. Printing excel document without opening
    By bihuboliya in forum Advanced Java
    Replies: 4
    Last Post: 03-22-2011, 02:32 AM
  2. printing string backwards and printing every other
    By droidus in forum New To Java
    Replies: 22
    Last Post: 03-10-2011, 09:17 AM
  3. set paper size on printing
    By jolly in forum NetBeans
    Replies: 0
    Last Post: 01-25-2011, 12:34 PM
  4. Replies: 1
    Last Post: 05-06-2010, 09:48 AM
  5. Setting frame size to the size of an image
    By Yoruichi in forum AWT / Swing
    Replies: 5
    Last Post: 04-22-2009, 04:37 PM

Posting Permissions

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