implements PrintServiceAttributeListener : PrintServiceAttributeListener « javax.print.event « Java by API






implements PrintServiceAttributeListener

  


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