Java Reference
In-Depth Information
The source code is shown in Example 12-10 .
Example 12-10. PrintServiceDemo.java
/**
* Show the latest incarnation of printing, PrintService, from a GUI;
* the GUI consists only of a "Print" button, and the filename is hardcoded,
* but it's meant to be a minimal demo...
*/
public
public class
class PrintServiceDemo
PrintServiceDemo extends
extends JFrame {
private
private static
static final
final long
long serialVersionUID = 923572304627926023L ;
private
private static
static final
final String INPUT_FILE_NAME = "/demo.txt" ;
/** main program: instantiate and show.
* @throws IOException */
public
public static
static void
void main ( String [] av ) throws
throws Exception {
SwingUtilities . invokeLater ( new
new Runnable () {
public
public void
void run () {
try
try {
new
new PrintServiceDemo ( "Print Demo" ). setVisible ( true
true );
} catch
catch ( Exception e ) {
e . printStackTrace ();
}
}
});
}
/** Constructor for GUI display with pushbutton to print */
PrintServiceDemo ( String title ) {
super
super ( title );
System . out . println ( "PrintServiceDemo.PrintServiceDemo()" );
setDefaultCloseOperation ( EXIT_ON_CLOSE );
setLayout ( new
new FlowLayout ());
JButton b ;
add ( b = new
new JButton ( "Print" ));
b . addActionListener ( new
new ActionListener () {
public
public void
void actionPerformed ( ActionEvent e ) {
System . out . println (
"PrintServiceDemo.PrintServiceDemo...actionPerformed()" );
try
try {
print ( INPUT_FILE_NAME );
} catch
catch ( Exception e1 ) {
JOptionPane . showMessageDialog (
PrintServiceDemo . this , "Error: " + e1 , "Error" ,
Search WWH ::




Custom Search