Solved

Printing from a Frame

Posted on 1998-09-01
11
274 Views
Last Modified: 2010-03-30
I have an applet that uses a frame to capture some input and then applies some calculations and maniulates the input and I use another frame to to display the data and I want to print the data in that frame - I can't seem to make it work...
0
Comment
Question by:mapper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 

Author Comment

by:mapper
ID: 1223244
Edited text of question
0
 
LVL 6

Expert Comment

by:gadio
ID: 1223245
mapper, in order to be able to print, your applet should be signed. Here is some reading material about signing an applet. If you need more info don't hesitate to ask.

Java signing FAQ: http://www.fastlane.net/~tlandry/javafaq.txt, that covers the latest versions of IE and Netscape, as well as the Java Activator.
Code signing: http://www.suitable.com/Doc_CodeSigning.shtml
 article about signing Applets for both IE and Netscape:
http://www.javareport.com/features/9801/sommers.html
Code signing for ActiveX is thoroughly detailed in
http://www.developer.com/reference/library/1575211610/ch23.htm
Security with ActiveX Authenticode appearing in http://www.gamelan.com
For Netscape Navigator, read about using the signing tool: http://developer.netscape.com/docs/manuals/signedobj/signtool/index.htm
programming with the Capabilities API: http://developer.netscape.com/docs/manuals/signedobj/capabilities/index.html
Object Signing Tool: http://developer.netscape.com/software/signedobj/jarpack.html
For Internet Explorer, the first article to read is:
http://www.microsoft.com/java/sdk/20/articles/trust_based_security.htm
And Signing a Cabinet File with java Permissions: http://www.microsoft.com/java/sdk/20/tools/signcode.htm
Also: http://www.microsoft.com/java/sdk/20/packages/security/default.htm
tools and documents are available for download in: http://www.microsoft.com/java/download.htm
Sun provides rudimentary tools for Signing and Verifying
JAR Files at:
http://www.javasoft.com/docs/books/tutorial/jar/sign/index.html (note that
they are not IE or NN compatible)

0
 
LVL 6

Expert Comment

by:gadio
ID: 1223246
Sorry there is some extra links that you dont need. The liks you need are:

Java signing FAQ: http://www.fastlane.net/~tlandry/javafaq.txt, that covers the latest versions of IE and Netscape, as well as the Java Activator.
Code signing: http://www.suitable.com/Doc_CodeSigning.shtml
article about signing Applets for both IE and Netscape: http://www.javareport.com/features/9801/sommers.html
For Netscape Navigator, read about using the signing tool: http://developer.netscape.com/docs/manuals/signedobj/signtool/index.htm
programming with the Capabilities API: http://developer.netscape.com/docs/manuals/signedobj/capabilities/index.html
Object Signing Tool: http://developer.netscape.com/software/signedobj/jarpack.html
For Internet Explorer, the first article to read is: http://www.microsoft.com/java/sdk/20/articles/trust_based_security.htm
And Signing a Cabinet File with java Permissions: http://www.microsoft.com/java/sdk/20/tools/signcode.htm
Also: http://www.microsoft.com/java/sdk/20/packages/security/default.htm
tools and documents are available for download in: http://www.microsoft.com/java/download.htm
Sun provides rudimentary tools for Signing and Verifying
JAR Files at:
http://www.javasoft.com/docs/books/tutorial/jar/sign/index.html (note that
they are not IE or NN compatible)

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:gadio
ID: 1223247
After the applet is signed, the normal printing scheme should work.
0
 

Author Comment

by:mapper
ID: 1223248
Here is the code I have so far:

            public void actionPerformed(ActionEvent e) {
                  if(e.getSource() == print) {

                          PrintJob prnJob;
                          Graphics pg = null;
                          try {
                        prnJob = getToolkit().getPrintJob(this, "Printing current frame", null);

                          } catch(Exception ex) {return;}
                        
                          if(prnJob!=null) {
                                    try {
                                        pg = prnJob.getGraphics();
                                    } catch(Exception ex) {return;}
                        }
                              if(pg!=null) {
                                  this.print(pg);
                                  pg.dispose();
                              }
                              prnJob.end();
                  }
                  else if(e.getSource() == exit) {
                        setVisible(false);
                        dispose();
            }
      }
}


I have looked over Gadio's input and that is too much for me to deal with is there any other options available??

Thanks,

mapper
0
 
LVL 2

Accepted Solution

by:
threshold earned 200 total points
ID: 1223249
mapper, gadio is right...
To print in Applet, we have to sign the applet, and if you use Netscape as your browser, you have to use the capabilites api.
There are something we should do for it:

1. sign the applet
2. if you don't want to sign the applet for development, you should enable the codebase principal.
    Find C:\....\Netscape\user\...\prefs.js and add a line (as below) into it.
        user_pref("signed.applets.codebase_principal_support", true);
3. import netscape.security.PrivilegeManager
4. write your java code

  try {
     PrivilegeManager.enablePrivilege("UniversalPropertyRead");
     ps.println("\tSuccess!");
  } catch (netscape.security.ForbiddenTargetException e) {
     ps.println("\tFailed! Permission to read system properties  denied by user.");
  } catch (Exception e) {
     ps.println("\tFailed! Unknown exception while enabling privilege.");
     e.printStackTrace(ps);
  }
 
  PrintJob prnJob;
  Graphics pg = null;
  try {
     prnJob = getToolkit().getPrintJob(this, "Printing current frame", null);
  } catch(Exception ex) {return;}
     if(prnJob!=null) {
  try {
     pg = prnJob.getGraphics();
  } catch(Exception ex) {return;}
  }
   if(pg!=null) {
      this.printAll(pg);  // use the printAll(...) to print frame and its child-component
      pg.dispose();
  }
  prnJob.end();

It's not good idea to print the component on the Screen, because maybe the component contains part of your data. We should create a invisible component as a print page(you can get the page dimension/resolution from printjob), and divide data into several pages , then print them.

If there is any trouble, please open the Java console and post the exceptions here.
0
 

Author Comment

by:mapper
ID: 1223250
Threshold,

I am not doubting Gadio's input - I guess I did not provide enough information or clarify what I meant well enough - It would be complety acceptable to print from the appletviewer - if that would preclude signing the applet - the code works on two different machines but not mine either at work or at home...

I am trying to figure out why it won't work on mine - I will check the preferences file and see if that has something (basically, look for the line you suggested) peculiar...

Please let me know - if there is something that will make it work in the appletviewer...

And I am sorry if I implied that either Gadio or your information was insuficient...

Thanks,

mapper
0
 
LVL 2

Expert Comment

by:threshold
ID: 1223251
I use the NS4.0x to print document in Java for a while, It's work well always.
but I never use the signed applet in appletviewer.
I can't tell you how to unlock the restriction of security in appletviewer.
Maybe, you can find the document about System.setSecurityManager(...) in JDK1.1.6 to help you.
0
 
LVL 6

Expert Comment

by:gadio
ID: 1223252
You have to use the javakey tool for that. You can find documentation in the sun site about the javakey.
0
 

Author Comment

by:mapper
ID: 1223253
Neither the browser at home or at work - had the line you suggested in the prefs file.  I did check the applet viewer out and set all to "Unrestricted"  that did not help - By "import netscape.security.PrivilegeManager" I am not too clear on what you mean - would that be one of the import lines at the top?  Import netscape.secruity.Privilege manager with the rest of the import calls?  Along with the first part of the code you provided would all of that go into the print method?  I am pretty sure it does but at this point - the frustration level is high an so is the confusion level...

Thanks for sticking with me - I am slow to learn - but that's because I take small bites and I chew each one 75 times!

mapper
0
 

Author Comment

by:mapper
ID: 1223254
threshold;

I have tried and tried to implement your code and I have had bupkis for luck to get it to compile - the code for me is too hard to figure out - using things I have never used previously....

I need or require some hand holding (I promise I don't kiss on the first date!)...

mapper
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question