Solved

Printing from a Frame

Posted on 1998-09-01
11
229 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now