1 /*
   2  * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import javax.print.*;
  25 import java.applet.*;
  26 import java.awt.*;
  27 
  28 public class Applet0 extends Applet {
  29 
  30     String name = "Applet 0 ";
  31     PrintService defServ = null;
  32     PrintService[] allServices = null;
  33     StreamPrintServiceFactory []fact = null;
  34 
  35     public void init() {
  36         defServ = PrintServiceLookup.lookupDefaultPrintService();
  37 
  38         allServices = PrintServiceLookup.lookupPrintServices(null,null);
  39 
  40       fact = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
  41               DocFlavor.SERVICE_FORMATTED.PRINTABLE,
  42               DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());
  43 
  44     }
  45 
  46     public void paint(Graphics g) {
  47       g.drawString("This is " + name, 10, 20);
  48       g.drawString("Default print service="+defServ,10,40);
  49       g.drawString("Number of print services="+allServices.length,10,60);
  50       g.drawString("Number of PS stream services="+fact.length,10,80);
  51       int y=100;
  52       for (int i=0;i<allServices.length;i++) {
  53           if (allServices[i].getName().startsWith("Applet ")) {
  54                g.drawString("Found service : "+allServices[i].getName(),10,y);
  55                y+=20;
  56            }
  57       }
  58     }
  59 
  60     public static void main(String[] args) {
  61         Applet0 applet = new Applet0();
  62         applet.init();
  63         Frame f = new Frame("Print Lookup Test");
  64         f.add(applet);
  65         f.setSize(300,200);
  66         f.show();
  67         }
  68 
  69 }