Java Reference
In-Depth Information
JOptionPane . ERROR_MESSAGE );
e1 . printStackTrace ();
}
}
});
pack ();
UtilGUI . center ( this
this );
}
/** Print a file by name
* @throws IOException
* @throws PrintException
*/
public
public void
throws IOException , PrintException {
System . out . println ( "PrintServiceDemo.print(): Printing " + fileName );
DocFlavor flavor = DocFlavor . INPUT_STREAM . TEXT_PLAIN_UTF_8 ;
PrintRequestAttributeSet aset = new
void print ( String fileName ) throws
new HashPrintRequestAttributeSet ();
//aset.add(MediaSize.NA.LETTER);
aset . add ( MediaSizeName . NA_LETTER );
//aset.add(new JobName(INPUT_FILE_NAME, null));
PrintService [] pservices =
PrintServiceLookup . lookupPrintServices ( flavor , aset );
int
int i ;
switch
switch ( pservices . length ) {
case
case 0 :
System . err . println ( 0 );
JOptionPane . showMessageDialog ( PrintServiceDemo . this ,
"Error: No PrintService Found" , "Error" ,
JOptionPane . ERROR_MESSAGE );
return
return ;
case
case 1 :
i = 0 ;
// Only one printer, use it.
break ;
default
break
default :
i = JOptionPane . showOptionDialog ( this
this ,
"Pick a printer" , "Choice" ,
JOptionPane . OK_OPTION , JOptionPane . QUESTION_MESSAGE ,
null
null , pservices , pservices [ 0 ]);
break
break ;
}
DocPrintJob pj = pservices [ i ]. createPrintJob ();
InputStream is = getClass (). getResourceAsStream ( INPUT_FILE_NAME );
iif ( is == null
null ) {
throw
throw new
new NullPointerException ( "Input Stream is null: file not found?" );
}
Doc doc = new
new SimpleDoc ( is , flavor , null
null );
Search WWH ::




Custom Search