The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.print.event  [3 examples]

e713. Listening for Print Service Status Changes

Examples of print service status include PrinterIsAcceptingJobs (indicates if a print service will accept new print jobs) and QueuedJobCount (the number of print jobs to be processed by the print service). Use a PrintServiceAttributeListener to get status changes on a print server. This example adds a listener to all print services. To obtain detailed status changes for a print job, see e714 Listening for Print Job Status Changes.
    // Add a listener to all print services
    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) {
            // Some event occurred with a print service
            PrintService service = psae.getPrintService();
    
            Attribute[] attrs = psae.getAttributes().toArray();
            for (int i=0; i<attrs.length; i++) {
                String attrName = attrs[i].getName();
    
                // New value
                String attrValue = attrs[i].toString();
                process(service, attrName, attrValue);
            }
        }
    }

 Related Examples
e714. Listening for Print Job Status Changes
e715. Listening for Print Job Attribute Changes


© 2002 Addison-Wesley.