java.lang.Object
java.awt.print.PrinterJob
- See Also:
- Top Examples, Source Code
public abstract void cancel()
- See Also:
print
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public PageFormat defaultPage()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract PageFormat defaultPage(PageFormat page)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract int getCopies()
- See Also:
setCopies(int)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract String getJobName()
- See Also:
setJobName(java.lang.String)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static PrinterJob getPrinterJob()
- See Also:
lookupPrintServices
, print
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[73]Simple print
By Anonymous on 2005/03/10 03:19:29 Rate
import java.awt.*;
import java.awt.print.*;
public class SimplePrint implements Printable {
private static Font fnt = new Font ( "Helvetica",Font.PLAIN,24 ) ;
public static void main ( String [ ] args ) {
// Get a PrinterJob
PrinterJob job = PrinterJob.getPrinterJob ( ) ;
// Specify the Printable is an instance of SimplePrint
job.setPrintable ( new SimplePrint ( ) ) ;
// Put up the dialog box
if ( job.printDialog ( ) ) {
// Print the job if the user didn't cancel printing
try { job.print ( ) ; }
catch ( Exception e )
{ }
}
System.exit ( 0 ) ;
}
public int print ( Graphics g, PageFormat pf, int pageIndex )
throws PrinterException {
// pageIndex 0 to 4 corresponds to page numbers 1 to 5.
if ( pageIndex > = 5 ) return Printable.NO_SUCH_PAGE;
g.setFont ( fnt ) ;
g.setColor ( Color.green ) ;
g.drawString ( "Page " + ( pageIndex+1 ) , 100, 100 ) ;
return Printable.PAGE_EXISTS;
}
}
public PrintService getPrintService()
- See Also:
setPrintService(PrintService)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[754]Select printer
By Anonymous on 2004/04/29 11:43:27 Rate
import java.awt.*;
import java.awt.geom.*;
import java.awt.print.*;
import javax.swing.*;
import java.awt.event.*;
public class SelectPrinter extends Component implements Printable {
private final double INCH = 66;
public String printer_name;
public String printer_n;
private int copies;
private PrinterJob printJob;
public SelectPrinter ( ) {
{
try
{
UIManager.setLookAndFeel ( UIManager.getSystemLookAndFeelClassName ( ) ) ;
SwingUtilities.updateComponentTreeUI ( this ) ;
}
catch ( Exception exception )
{
exception.printStackTrace ( ) ;
}
}
//--- Create a printerJob object
try {
printJob = PrinterJob.getPrinterJob ( ) ;
}
catch ( Exception e )
{
JOptionPane.showMessageDialog ( null,e.getMessage ( ) ) ;
}
//--- Set the printable class to this one since we
//--- are implementing the Printable interface
printJob.setPrintable ( this ) ;
}
public void showPrinterDialog ( )
{
if ( printJob.printDialog ( ) )
printer_name = printJob.getPrintService ( ) .getName ( ) ;
printer_n = printer_name.trim ( ) ;
}
public String getPrinter_name ( )
{
return printer_name;
}
public String getPrinter_n ( )
{
return printer_n;
}
public void setPrinter_name ( String printer_name )
{
}
public void setPrinter_n ( String printer_n )
{
}
public int print ( Graphics g, PageFormat pageFormat, int page ) {
int i;
Graphics2D g2d;
Line2D.Double line = new Line2D.Double ( ) ;
//--- Validate the page number, we only print the first page
if ( page == 0 ) {
//--- Create a graphic2D object and set the default parameters
g2d = ( Graphics2D ) g;
g2d.setColor ( Color.black ) ;
//--- Translate the origin to be ( 0,0 )
g2d.translate ( pageFormat.getImageableX ( ) , pageFormat.getImageableY ( ) ) ;
//--- Print the vertical lines
for ( i = 0; i < pageFormat.getWidth ( ) ; i += INCH / 2 ) {
line.setLine ( i, 0, i, pageFormat.getHeight ( ) ) ;
g2d.draw ( line ) ;
}
//--- Print the horizontal lines
for ( i = 0; i < pageFormat.getHeight ( ) ; i += INCH / 2 ) {
line.setLine ( 0, i, pageFormat.getWidth ( ) , i ) ;
g2d.draw ( line ) ;
}
return ( PAGE_EXISTS ) ;
}
else
return ( NO_SUCH_PAGE ) ;
}
}
public abstract String getUserName()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract boolean isCancelled()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static PrintService[] lookupPrintServices()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static StreamPrintServiceFactory[] lookupStreamPrintServices(String mimeType)
- See Also:
StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract PageFormat pageDialog(PageFormat page)
throws HeadlessException
- See Also:
GraphicsEnvironment.isHeadless()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public PageFormat pageDialog(PrintRequestAttributeSet attributes)
throws HeadlessException
- See Also:
GraphicsEnvironment.isHeadless()
, NullPointerException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract void print()
throws PrinterException
- See Also:
Printable
, Pageable
, Book
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void print(PrintRequestAttributeSet attributes)
throws PrinterException
- See Also:
Printable
, Pageable
, Book
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract boolean printDialog()
throws HeadlessException
- See Also:
GraphicsEnvironment.isHeadless()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public boolean printDialog(PrintRequestAttributeSet attributes)
throws HeadlessException
- See Also:
GraphicsEnvironment.isHeadless()
, NullPointerException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public PrinterJob()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract void setCopies(int copies)
- See Also:
getCopies()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract void setJobName(String jobName)
- See Also:
getJobName()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract void setPageable(Pageable document)
throws NullPointerException
- See Also:
Printable
, PageFormat
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract void setPrintable(Printable painter)
- See Also:
PageFormat
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract void setPrintable(Printable painter,
PageFormat format)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void setPrintService(PrintService service)
throws PrinterException
- See Also:
getPrintService()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract PageFormat validatePage(PageFormat page)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples