This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Applets and the fly likes java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot) Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot) Exception" Watch "java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot) Exception" New topic
Author

java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot) Exception

Madhu Menda
Greenhorn

Joined: May 30, 2011
Posts: 7
Hi All,

I've write the code to take the screenshots :

package screenshot;

import java.applet.Applet;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.text.SimpleDateFormat;
import javax.imageio.ImageIO;
import java.util.*;

public class TakeSnap extends Applet {
public void paint (Graphics g) {

SimpleDateFormat sd = new SimpleDateFormat("yyyyMMddHs");
Date d = new Date();
String dateNow = sd.format(d);
g.drawString("Hi My Boss created me: "+dateNow, 50,50);
AWTPermission per = new AWTPermission( "createRobot" );

Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Rectangle rectangle = new Rectangle(0, 0, screenSize.width, screenSize.height);
try{

Robot robot = new Robot();


while(true){
d = new Date();
dateNow = sd.format(d);
Thread.sleep(2000);
BufferedImage image = robot.createScreenCapture(rectangle);
File file=new File("d:\\sc\\sc"+dateNow+".jpg");
ImageIO.write(image,"jpg", file);

}
}catch(Exception e){
e.printStackTrace();
}
}
}


the above code is gets executed from netbeans(right click and run ) but from the command prompt it is giving the following error.


java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:323)
at java.security.AccessController.checkPermission(AccessController.java:
546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.awt.Robot.checkRobotAllowed(Robot.java:126)
at java.awt.Robot.init(Robot.java:114)
at java.awt.Robot.<init>(Robot.java:76)
at screenshot.TakeSnap.paint(TakeSnap.java:33)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:301)
at java.awt.Component.dispatchEventImpl(Component.java:4486)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

please help me
-------
Thank in advance
Madhu
Madhu Menda
Greenhorn

Joined: May 30, 2011
Posts: 7
Madhu Menda wrote: Hi All,

I've write the code to take the screenshots :

package screenshot;

import java.applet.Applet;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.text.SimpleDateFormat;
import javax.imageio.ImageIO;
import java.util.*;

public class TakeSnap extends Applet {
public void paint (Graphics g) {

SimpleDateFormat sd = new SimpleDateFormat("yyyyMMddHs");
Date d = new Date();
String dateNow = sd.format(d);
g.drawString("Hi My Boss created me: "+dateNow, 50,50);
AWTPermission per = new AWTPermission( "createRobot" );

Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Rectangle rectangle = new Rectangle(0, 0, screenSize.width, screenSize.height);
try{

Robot robot = new Robot();


while(true){
d = new Date();
dateNow = sd.format(d);
Thread.sleep(2000);
BufferedImage image = robot.createScreenCapture(rectangle);
File file=new File("d:\\sc\\sc"+dateNow+".jpg");
ImageIO.write(image,"jpg", file);

}
}catch(Exception e){
e.printStackTrace();
}
}
}


the above code is gets executed from netbeans(right click and run ) but from the command prompt it is giving the following error.


java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:323)
at java.security.AccessController.checkPermission(AccessController.java:
546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.awt.Robot.checkRobotAllowed(Robot.java:126)
at java.awt.Robot.init(Robot.java:114)
at java.awt.Robot.<init>(Robot.java:76)
at screenshot.TakeSnap.paint(TakeSnap.java:33)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:301)
at java.awt.Component.dispatchEventImpl(Component.java:4486)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

please help me
-------
Thank in advance
Madhu



Hi all i added the following entries in java.policy file

permission java.awt.AWTPermission "createRobot";
permission java.awt.AWTPermission "accessClipboard";
permission java.awt.AWTPermission "accessEventQueue";
permission java.awt.AWTPermission "showWindowWithoutWarningBanner";
permission java.awt.AWTPermission "readDisplayPixels", "read";

permission java.io.FilePermission "<<ALL FILES>>", "read, write, delete, execute";


the problem got solved....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot) Exception
 
Similar Threads
to copy a policy file from server machine to client machine in java
AccessControlException When Capture screen with Applet
database access and applet
AccessControlException When Capture screen with Applet
desktop ScreenShot