PrintService: addPrintServiceAttributeListener(PrintServiceAttributeListener listener) : PrintService « javax.print « Java by API






PrintService: addPrintServiceAttributeListener(PrintServiceAttributeListener listener)

  

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();
    }
  }
}

   
    
  








Related examples in the same category

1.PrintService: createPrintJob()
2.PrintService: getDefaultAttributeValue(Class arg0)
3.PrintService: getSupportedAttributeCategories()
4.PrintService: getSupportedDocFlavors()