Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4099584
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:27:11+00:00 2026-05-20T20:27:11+00:00

I have designed an Applet to take a screenshot and save it on the

  • 0

I have designed an Applet to take a screenshot and save it on the users computer using the java.awt.Robot class. I need to embedd this applet into an html page (using the object tag) so that when the user clicks a button on the webpage the screenshot is taken.

The applet itself works fine, i’ve tested it by adding a temporary main method to it and running it on my local machine as a regular java app.

Where I’m having difficulty is setting up permissions to allow it to run from its embedded location. Obviously the robot class is somewhat hazardous so an AWTPermission needs to be established and the applet itself needs to be signed.

I followed through the tutorial at http://download.oracle.com/javase/tutorial/security/toolsign/index.html and succeeded in creating a signed .jar file and then a policy file that allowed the demo application in that tutorial to run. Where I am now running into issues is how to reconcile what I’ve learned with the situation my applet will be used in.

My target audience comprises around 100 machines and I need it to be executable on all of them. I have packed my java .class file into a .jar and signed it using keytool and jarsigner. I then uploaded the .jar and .cer files to the server directory where the pages in question are hosted.

However: When I then used policytool to create a new policy file on one of the machines to test the setup I am still unable to execute the applet from the HTML. I get Java.Security.AccessControlException Acess Denied java.awt.AWTPermission createRobot errors.

I rather suspect its the policy step that is going awry, so I’ll outline the steps I took:
I download the certificate to the local machine and generate a keystore from it, I launch ‘policytool’ from this directory through the commandline
I add the directory on the local machine where the keystore generated from and my certificate is located.
I then hit the add policy button and enter the SignedBy alias
Then Add Permissions and select AWTPermission
Targets name I select createRobot
The function field I have been leaving blank as I cant think what would apply here
Signed By in this window is also left blank
I then hit ‘OK’ and ‘Done’ and get a warning that there is no public key for the alias I’ve entered in the first step. I do a ‘save as’ and save my policyfile to the same directory as I put the certificate and the keystore generated from it.

This is not allowing me to run the applet from the webpage however and my limited understanding of this aspect of programming offers no clues as to what has gone wrong.

Ideas, thoughts, observations? If I havent explicitly mentioned something then I havent done it. My biggest suspect is the warning I recieve but I cant seem to find why its appearing

EDIT: Forgot to mention a step. I manually added to my jre\lib\security\java.security file the line ‘policy.url.3=file:/C:/Testing/debugpolicy’ since thats the path and policy filename I created during the above steps. I also just now managed to remove the warning I mentioned earlier, I’d been mixing up my alias’ and gave the alias for the private keystore rather than the public one during policyfile creation, however I still encounter the same problems

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:27:12+00:00Added an answer on May 20, 2026 at 8:27 pm

    If an applet is correctly signed, no policy file is required, nor is it required to separately upload any certificate. A correctly signed applet will prompt the user for permission when the applet is visited, before it loads. Does the prompt appear?

    Here is a small demo. I wrote that demonstrates Defensive loading of trusted applets. That is the security prompt I am referring to.

    If the applet is both digitally signed by the developer and trusted by the end user, it should be able to take a screen-shot.

    There is one other thing you might try if the applet is trusted, just as an experiment (1). Early in the applet init(), call System.setSecurityManager(null). That will both test if the applet has trust, and wipe away the last remnants of the ‘trusted’ security manager given to applets.

    And in the case that works, and it makes the screen capture successful, it suggests either a bug or Oracle changed their mind about the defaults of what a trusted applet could do.

    1) Don’t do this in a real world or production environment. To quote Tom Hawtin:

    This question appears to have given some the impression that calling System.setSecurityManager(null); is okay. … In case anyone has any doubts, changing global state in an applet will affect all applets in the same process. Clearing the security manager will allow any unsigned applet to do what it likes. Please don’t sign code that plays with global state with a certificate you expect anyone to trust.


    Edit 1:
    Here is the source of the simple applet used in that demo. For some reason when I originally uploaded it, I decided the source was not relevant. OTOH 3 people have now asked to see the source, for one reason or another. When I get a round tuit I’ll upload the source to my site. In the mean time, I’ll put it here.

    package org.pscode.eg.docload;
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.net.*;
    import java.io.*;
    import java.security.*;
    
    /** An applet to display documents that are JEditorPane compatible. */
    public class DocumentLoader extends JApplet {
        JEditorPane document;
    
        @Override
        public void init() {
            System.out.println("init()");
    
            JPanel main = new JPanel();
            main.setLayout( new BorderLayout() );
            getContentPane().add(main);
            try {
                // It might seem odd that a sandboxed applet can /instantiate/
                // a File object, but until it goes to do anything with it, the
                // JVM considers it 'OK'.  Until we go to do anything with a
                // 'File' object, it is really just a filename.
                File f = new File(".");
    
                // set up the green 'sandboxed page', as a precaution..
                URL sandboxed = new URL(getDocumentBase(), "sandbox.html");
                document = new JEditorPane(sandboxed);
                main.add( new JScrollPane(document), BorderLayout.CENTER );
                // Everything above here is possible for a sandboxed applet
    
                // *test* if this applet is sandboxed
                final JFileChooser jfc =
                    new JFileChooser(f); // invokes security check
                jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                jfc.setMultiSelectionEnabled(false);
    
                JButton button = new JButton("Load Document");
                button.addActionListener( new ActionListener(){
                        public void actionPerformed(ActionEvent ae) {
                            int result = jfc.showOpenDialog(
                                DocumentLoader.this);
                            if ( result==JFileChooser.APPROVE_OPTION ) {
                                File temp = jfc.getSelectedFile();
                                try {
                                    URL page = temp.toURI().toURL();
                                    document.setPage( page );
                                } catch(Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    } );
                main.add( button, BorderLayout.SOUTH );
    
                // the applet is trusted, change to the red 'welcome page'
                URL trusted = new URL(getDocumentBase(), "trusted.html");
                document.setPage(trusted);
            } catch (MalformedURLException murle) {
                murle.printStackTrace();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            } catch (AccessControlException ace) {
                ace.printStackTrace();
            }
        }
    
        @Override
        public void start() {
            System.out.println("start()");
        }
    
        @Override
        public void stop() {
            System.out.println("stop()");
        }
    
        @Override
        public void destroy() {
            System.out.println("destroy()");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have designed some classes using Visual Studio class diagramming. Now I would like
I have to integrate a Java applet into a simple asp.net 2.0 control. This
I have designed a class which is basically nothing but an object which stores
I have designed a chess board using loops in php. The board is all
I have designed an ERD for a website I am about to build. This
I have designed what is essentially a propertychanged listener - i.e. when Instance.A changes,
I have designed an app for android tablets and it consists of a tab
I have designed a web page where on the left there is a div
I have designed database tables (normalised, on an MS SQL server) and created a
I have Designed the Javascript function My.js it contains following code My.js function display(){

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.