Problem printing from Applet....

I am having trouble getting printing to work from an applet. My code is JDK 1.1.8 and my browser is Netscape 4.5. My applet is signed and I am getting the Print dialog just fine. However, the actual printing is failing. Please advise me in the errors of my ways...

Here is my printing routine...

public void getData()
   {
      try
      {
         textArea.append("Hello World!!!!!\n");

         PrivilegeManager.enablePrivilege("UniversalPrintJobAccess");

         Toolkit tk = Toolkit.getDefaultToolkit();
         PrintJob pj = tk.getPrintJob(new Frame(), "Print Test", null);

         if (pj == null) return;

         pageWidth = pj.getPageDimension().width;
         pageHeight= pj.getPageDimension().height;

         Graphics g = pj.getGraphics();

         g.drawString(textArea.getText(), 50, 50);

         pj.end();
         g.dispose();
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
   }

Here is the error stack trace...

java.lang.NullPointerException
  at sun.awt.windows.WGraphics.drawChars(Compiled Code)
* at sun.awt.windows.WGraphics.drawString(Compiled Code)
  at PrintTest.getData(Compiled Code)
  at PrintTest.start(Compiled Code)
  at netscape.applet.DerivedAppletFrame$StartAppletEvent.dispatch(Compiled Code)
  at java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled Code)
  at java.awt.EventDispatchThread.run(Compiled Code)
  at netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled Code)


Thanks in Advance!!!

dmanzana

dmanzanaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

heyhey_Commented:
what happens if you replace
textArea.getText()
with a static String ('Hello')
0
dmanzanaAuthor Commented:
Changing textArea.getText() to a static string "Hello" does not change anything. The exact error still occurs.

dmanzana
0
heyhey_Commented:
just another (better) idea
your frame is not Visible so it does not have a peer

replace
   PrintJob pj = tk.getPrintJob(new Frame(), "Print Test", null);
with
Frame f = new Frame();
f.addNotify();
PrintJob pj = tk.getPrintJob(f, "Print Test", null);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

dmanzanaAuthor Commented:
No luck. The same problem is happening. I really appreciate your time and effort in helping me with this.

dmanzana
0
dmanzanaAuthor Commented:
I have found the problem. The Color and Font within the Graphics were null. As soon as I instantiated a Color and Font and passed them into the Graphics, all is well. Thanks for your efforts. I will give you the points anyway.

dmanzana
0
heyhey_Commented:
thanks :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.