Listening for Print Service Status Changes : Print Service « 2D Graphics « Java Tutorial






import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.Attribute;
import javax.print.event.PrintServiceAttributeEvent;
import javax.print.event.PrintServiceAttributeListener;

public class Main {
  public static void main(String[] argv) throws Exception {
    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
    for (int i = 0; i < services.length; i++) {
      services[i].addPrintServiceAttributeListener(new MyPrintServiceAttributeListener());
    }
  }
}

class MyPrintServiceAttributeListener implements PrintServiceAttributeListener {
  public void attributeUpdate(PrintServiceAttributeEvent psae) {
    PrintService service = psae.getPrintService();
    Attribute[] attrs = psae.getAttributes().toArray();
    for (int i = 0; i < attrs.length; i++) {
      String attrName = attrs[i].getName();
      String attrValue = attrs[i].toString();
    }
  }
}








16.51.Print Service
16.51.1.List Print Services
16.51.2.Using a Printing Service
16.51.3.Using a Streaming Printing Service
16.51.4.Discovering Available Print Services
16.51.5.Discovering Available Streaming Print Services
16.51.6.Use a factory to create a print service
16.51.7.Listening for Print Service Status Changes
16.51.8.Listening for Print Job Status Changes
16.51.9.Determining the Capabilities of a Print Service
16.51.10.Determining Print Job Capabilities Supported by a Print Service