Results 1 to 2 of 2
  1. #1
    JimBobJr is offline Member
    Join Date
    Apr 2012
    Posts
    1
    Rep Power
    0

    Default Applet access denied error

    I have been banging my head around this for 2 days, and can not figure it out. It runs fine, until I try it as an applet.

    This is the error I am getting

    java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0)
    at java.security.AccessControlContext.checkPermission (AccessControlContext.java:374)
    at java.security.AccessController.checkPermission(Acc essController.java:546)
    at java.lang.SecurityManager.checkPermission(Security Manager.java:532)
    at java.lang.SecurityManager.checkExit(SecurityManage r.java:744)
    at javax.swing.JFrame.setDefaultCloseOperation(JFrame .java:372)
    at JRockPaperScissors.initializeComponent(JRockPaperS cissors.java:115)
    at JRockPaperScissors.<init>(JRockPaperScissors.java: 31)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Construc tor.java:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)
    at sun.applet.AppletPanel.createApplet(AppletPanel.ja va:785)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java: 714)
    at sun.applet.AppletPanel.run(AppletPanel.java:368)
    at java.lang.Thread.run(Thread.java:662)
    All I know is that it is on line 31, I have been trying to figure out another way to initialize but no success.

    Here is the code:

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Random;
    import javax.swing.JApplet;
    
    
    /** rock paper scissors class */
    public class JRockPaperScissors extends JApplet{
          	// Variables declaration
    			
    
          private JLabel titleLbl;
          private JLabel selectionLbl;
       	private JLabel resultsLbl;
       	private JTextArea resultTextArea;
       	private JButton rockBn;
       	private JButton paperBn;
       	private JButton scissorBn;
       	private Container contentPane;
          private int cpu = 0;
          private int wins = 0;
          private int loses = 0;
          private int ties = 0;
          private final int CHOICE_MAX = 3;
          private final int ROCK = 0;
          private final int PAPER = 1;
          private final int SCISSORS = 2;
          private Random rand = new Random();
    
    	public JRockPaperScissors(){
      	initializeComponent();
    	}
            /** initializing componets */
    	private void initializeComponent()
    	{
    		titleLbl = new JLabel();
    		selectionLbl = new JLabel();
    		resultsLbl = new JLabel();
    		resultTextArea = new JTextArea();
    		rockBn = new JButton();
    		paperBn = new JButton();
    		scissorBn = new JButton();
    		contentPane = getContentPane();
    
    		//
    		// titleLbl
    		//
    		titleLbl.setText("Rock, Paper, Scissors");
                    titleLbl.setFont(new Font("Garrmond", Font.BOLD, 30));
    		//
    		// selectionLbl
    		//
    		selectionLbl.setText("Choose one");
                    selectionLbl.setFont(new Font("Arial",Font.BOLD,14));
    		//
    		// resultsLbl
    		//
    		resultsLbl.setText("*****Results*****");
                    selectionLbl.setFont(new Font("Arial",Font.BOLD,14));
    		//
    		// resultTextArea
    		//
    	
    
                    
    		//
    		// rockBn
    		//
    		rockBn.setText("Rock");
    		rockBn.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e)
    			{
    				rockBn_actionPerformed(e);
    			}
    
    		});
    		//
    		// paperBn
    		//
    		paperBn.setText("Paper");
    		paperBn.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e)
    			{
    				paperBn_actionPerformed(e);
    			}
    
    		});
    		//
    		// scissorBn
    		//
    		scissorBn.setText("Scissors");               
    		scissorBn.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e)
    			{
    				scissorBn_actionPerformed(e);
    			}
    
    		});
    		//
    		// contentPane
    		//
    		contentPane.setLayout(null);
    		addComponent(contentPane, titleLbl, 5,9,370,47);
    		addComponent(contentPane, selectionLbl, 9,54,150,35);
    		addComponent(contentPane, resultsLbl, 9,93,144,38);
    		addComponent(contentPane, resultTextArea, 5,132,398,111);
    		addComponent(contentPane, rockBn, 162,58,78,31);
    		addComponent(contentPane, paperBn, 247,58,81,31);
    		addComponent(contentPane, scissorBn, 334,58,87,31);
    		contentPane.setSize(new Dimension(435, 290));
    		//
    		// JRockPaperScissors
    		//		
    		setTitle("Paper Rock Scissors");
    		setSize(435, 290);
    		setVisible(true);
    	}
    
    	/** Add Component Without a Layout Manager (Absolute Positioning) */
    	private void addComponent(Container container,Component c,int x,int y,int width,int height)
    	{
    		c.setBounds(x,y,width,height);
    		container.add(c);
    	}
    
    	/** action event methods */
    	private void rockBn_actionPerformed(ActionEvent e)
    	{
                //play the game choosing rock
                play(ROCK);
    	}
    
    	private void paperBn_actionPerformed(ActionEvent e)
    	{
                //play the game choosing paper
                play(PAPER);
    	}
    
    	private void scissorBn_actionPerformed(ActionEvent e)
    	{
                //play the game choosing scissors
                play(SCISSORS);
    	}
            //method to play the game
            private void play(int pick){
                 String resultStr = "";                   
                 //random computer choice
                 cpu = rand.nextInt(CHOICE_MAX);
                 //nested if statments to determine winner loser or tie
                 if(pick == cpu){
                     ties++;
                     resultStr = "You picked " + selection(pick) + " ---- Computer picked " + selection(cpu);
                     resultStr += "\nWinner: Tie";
                     resultStr += "\nYou: " + Integer.toString(wins) + "  " + "Computer: " + Integer.toString(loses) + " Ties: " + Integer.toString(ties);
                     resultTextArea.setText(resultStr);
                 }
                 else if( (pick == ROCK) && (cpu == SCISSORS) ){
                     wins++;
                     resultStr = "You picked " + selection(pick) + " ---- Computer picked " + selection(cpu);
                     resultStr += "\nWinner: You";
                     resultStr += "\nYou: " + Integer.toString(wins) + "  " + "Computer: " + Integer.toString(loses) + " Ties: " + Integer.toString(ties);
                     resultTextArea.setText(resultStr);
                 }
                 else if( (pick == PAPER) && (cpu == ROCK) ){
                     wins++;
                     resultStr = "You picked " + selection(pick) + " ---- Computer picked " + selection(cpu);
                     resultStr += "\nWinner: You";
                     resultStr += "\nYou: " + Integer.toString(wins) + "  " + "Computer: " + Integer.toString(loses) + " Ties: " + Integer.toString(ties);
                     resultTextArea.setText(resultStr);                 
                 }
                 else if( (pick == SCISSORS) && (cpu == PAPER) ){
                     wins++;
                     resultStr = "You picked " + selection(pick) + " ---- Computer picked " + selection(cpu);
                     resultStr += "\nWinner: You";
                     resultStr += "\nYou: " + Integer.toString(wins) + "  " + "Computer: " + Integer.toString(loses) + " Ties: " + Integer.toString(ties);
                     resultTextArea.setText(resultStr);
                 }
                 else{
                     loses++;
                     resultStr = "You picked " + selection(pick) + " ---- Computer picked " + selection(cpu);
                     resultStr += "\nWinner: Computer";
                     resultStr += "\nYou: " + Integer.toString(wins) + "  " + "Computer: " + Integer.toString(loses) + " Ties: " + Integer.toString(ties);
                     resultTextArea.setText(resultStr);                 
                 }
                 
            }
                //function returns paper rock or scissors as a string
                 public String selection(int choice){
                     String tempStr;
                     switch(choice){
                       case 0:
                             tempStr = "rock";
                             break;
                       case 1:
                             tempStr = "paper";
                             break;
                       case 2:
                             tempStr = "scissors";
                             break;
                       default:
                             tempStr = "invalid";
                      }
                      return tempStr;
                 }
    
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Moderator
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    9,928
    Rep Power
    16

    Default Re: Applet access denied error

    Quote Originally Posted by JimBobJr View Post
    This is the error I am getting
    java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0)
    :
    :
    at javax.swing.JFrame.setDefaultCloseOperation(JFrame.java:372)
    at JRockPaperScissors.initializeComponent(JRockPaperScissors.java:115)
    at JRockPaperScissors.<init>(JRockPaperScissors.java: 31)
    :
    :
    All I know is that it is on line 31
    Take a closer look at the stack trace.

    db
    Why do they call it rush hour when nothing moves? - Robin Williams

Similar Threads

  1. Jni registry 'access denied' error.
    By durino13 in forum Advanced Java
    Replies: 4
    Last Post: 09-17-2011, 07:06 AM
  2. Replies: 1
    Last Post: 05-17-2011, 08:05 PM
  3. Access Denied Error using applets
    By vin_eets in forum Java Applets
    Replies: 0
    Last Post: 04-01-2011, 02:19 PM
  4. newbie here, access denied error?!?
    By kingpabs in forum JCreator
    Replies: 3
    Last Post: 04-01-2011, 02:16 AM
  5. [SOLVED] Access Denied error using FileInputStream
    By xcallmejudasx in forum New To Java
    Replies: 8
    Last Post: 05-21-2009, 04:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •