Java Reference
In-Depth Information
L ISTING 11.9 Continued
11
import javax.jnlp.*;
import java.awt.*;
/**
* Chapter 11 - An example of printing via JNLP API
* @author Mauro Marinilli
* @version 1.0
*/
public class PrintServiceExample {
public PrintServiceExample() {
PrintService ps =
(PrintService)Utilities.getService(“javax.jnlp.PrintService”);
ps.print(new PrintableExample());
System.exit(0);
}
public class PrintableExample implements Printable {
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex){
Graphics2D g2d = (Graphics2D)graphics;
g2d.setPaint(Color.black);
g2d.drawString(“A JNLP Print”,100,100);
return PAGE_EXISTS;
}
}
public static void main(String[] args) {
PrintServiceExample printServiceExample1 = new PrintServiceExample();
}
}
An Example Application
As a recapping example of what said, let's take a look at Listing 11.10, in which an application
uses many of the things discussed in this chapter. As we can see, we are constantly moving
toward a full-fledged application, such as the one presented in Chapter 13.
L ISTING 11.10 A Recapping Example of JNLP Runtime Services at Work
package com.marinilli.b2.c11;
import com.marinilli.b2.c11.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.jnlp.*;
import java.net.URL;
import java.io.*;
import java.util.Iterator;
Search WWH ::




Custom Search