Jump to content
  • Advertisement
Sign in to follow this  
Thoover

[java] Printing From Java Applet

This topic is 3157 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been looking for about 3 hours, it will come up with the print dialog but never prints, here is the code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.print.*;
import java.awt.print.PageFormat;
import java.lang.String;
import java.io.*;
import java.util.*;
import java.applet.Applet;
import java.awt.GridLayout;
import java.awt.TextArea;


public class label extends JApplet implements Printable
{
	String one = "";
	String two = "";
	public void init() 
	{
		one=getParameter("one");
		two=getParameter("two");
		PrinterJob job = PrinterJob.getPrinterJob();
         job.setPrintable(this);
         boolean ok = job.printDialog();
         if (ok) {
             try {
                  job.print();
             } catch (PrinterException ex) {
              System.out.println("ERR");/* The job did not successfully complete */
             }
         }
	}
	
     public int print(Graphics g, PageFormat pf, int page) throws
                                                        PrinterException {

        if (page > 0) { /* We have only one page, and 'page' is zero-based */
            return NO_SUCH_PAGE;
        }

        /* User (0,0) is typically outside the imageable area, so we must
         * translate by the X and Y values in the PageFormat to avoid clipping
         */
        Graphics2D g2d = (Graphics2D)g;
        g2d.translate(pf.getImageableX(), pf.getImageableY());
	g.setColor(Color.decode("0x000000"));
        /* Now we perform our rendering */
        g.drawString(one, 2, 10);
        g.drawString(two, 2, 50);
        /* tell the caller that this page is part of the printed document */
        return PAGE_EXISTS;
    }
}

any help appreciated P.S. this is printing to a SLP240

Share this post


Link to post
Share on other sites
Advertisement
You might be running into a security exception. Run your applet one more time, and check your Java console (on Windows, right-click the Java icon on your task bar and select "Open Java Console"). If you are indeed running into a security exception, then you will have to sign your applet.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!