e713. listening for print service status changes.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 24 行

TXT
24
字号
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);
            }
        }
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?