Results 1 to 2 of 2
  1. #1
    IYIaster is offline Member
    Join Date
    Jul 2009
    Posts
    46
    Rep Power
    0

    Default trying to print a text file.

    I'm working on a txt file that I want to print.

    Java Code:
     FileInputStream textStream;
                textStream = new FileInputStream("C://mew.txt");
                DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
                Doc mydoc = new SimpleDoc(textStream, flavor, null);
                PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, aset);
                PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
                if (services.length == 0) {
                    if (defaultService == null) {
                        //no printer found
                    } else {
                        //print using default
                        DocPrintJob job = defaultService.createPrintJob();
                        job.print(mydoc, aset);
                    }
                } else {
                    //built in UI for printing you may not use this
                    PrintService service = ServiceUI.printDialog(null, 200, 200, services, defaultService, flavor, aset);
                    if (service != null) {
                        DocPrintJob job = service.createPrintJob();
                        job.print(mydoc, aset);
                    }
                }
            } catch (FileNotFoundException ex) {
                Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
    For some reason all of the "aset" are underlined and say: "lookupPrintServices(javax.print.DocFlavor,javax.p rint.attribute.AttributeSet) in javax.print.PrintServiceLookup cannot be applied to (javax.print.DocFlavor,aset)"

    Also when I run the program I get this error:

    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code
    at my.NewJFrame.NewJFrame.jButton1ActionPerformed(New JFrame.java:1970)
    at my.NewJFrame.NewJFrame.access$2400(NewJFrame.java: 38)
    at my.NewJFrame.NewJFrame$24.actionPerformed(NewJFram e.java:645)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1849)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2169)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:420)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:258)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:5501)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3135)
    at java.awt.Component.processEvent(Component.java:526 6)
    at java.awt.Container.processEvent(Container.java:196 6)
    at java.awt.Component.dispatchEventImpl(Component.jav a:3968)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2024)
    at java.awt.Component.dispatchEvent(Component.java:38 03)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4212)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:3892)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:3822)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2010)
    at java.awt.Window.dispatchEventImpl(Window.java:1778 )
    at java.awt.Component.dispatchEvent(Component.java:38 03)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 463)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:157)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:149)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:110)
    BUILD SUCCESSFUL (total time: 14 seconds)

    This is my first time trying to print something Thanks for any help.

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You have to compile the source code before attempting to run it.
    Read the API specs for the lookupPrintServices method to see the parameters that it expects and compare them with what you are passing it.

Similar Threads

  1. How to print text file in java(dotmatrix printer)
    By yoganeethi in forum Advanced Java
    Replies: 4
    Last Post: 12-01-2010, 02:45 PM
  2. Print .prn file using java
    By nishant in forum Advanced Java
    Replies: 0
    Last Post: 07-14-2009, 10:15 AM
  3. Replies: 6
    Last Post: 04-09-2009, 03:11 AM
  4. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 12:04 AM
  5. Print a picture file
    By oli001 in forum New To Java
    Replies: 0
    Last Post: 11-26-2007, 02:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •