aspose file tools*
The moose likes Applets and the fly likes Java RMC popup applet error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Java RMC popup applet error" Watch "Java RMC popup applet error" New topic
Author

Java RMC popup applet error

Al Murphy Al Murphy
Greenhorn

Joined: Feb 03, 2004
Posts: 16
Folks,
Interesting one here. I've implemented a right mouse click popup menu thingy that I found somewhere (code included below).
It works perfectly using the appletviewer but when I view it in IE6.0 & NN7.1 I get the following error message "java.security.AccessControlException: access denied (java.awt.AWTPermission accessClipboard)" Full error message under this.
I would greatly appreciate your comemnts and suggestions on this...
Thanks,
Al
****** ERROR MESSAGE AS FOLLOWS *******
Java(TM) Plug-in: Version 1.4.2_03
Using JRE version 1.4.2_03 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\amurphy
Proxy Configuration: Browser Proxy Configuration
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
p: reload proxy configuration
q: hide console
r: reload policy configuration
s: dump system properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
java.security.AccessControlException: access denied (java.awt.AWTPermission accessClipboard)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkSystemClipboardAccess(Unknown Source)
at sun.awt.windows.WToolkit.getSystemClipboard(Unknown Source)
at PopupMenuMouseListener.mouseClicked(PopupMenuMouseListener.java:142)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
java.security.AccessControlException: access denied (java.awt.AWTPermission accessClipboard)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkSystemClipboardAccess(Unknown Source)
at sun.awt.windows.WToolkit.getSystemClipboard(Unknown Source)
at PopupMenuMouseListener.mouseClicked(PopupMenuMouseListener.java:142)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
****** END ERROR MESSAGE ******
CODE AS FOLLOWS:
public class Widgets extends JApplet
{
int appletWidth, appletHeight;
JPanel P1;
JTextField jtfInput;
JTextArea jtaOutput;
PopupMenuMouseListener pmml = new PopupMenuMouseListener();

public void init()
{
// Physical dimensions of the applet
Dimension d = getSize();
appletWidth = d.width;
appletHeight = d.height;
// Colors of the applet
getContentPane().setBackground(Color.black);
getContentPane().setForeground(Color.white);
getContentPane().setLayout(new BorderLayout());

P1 = new JPanel();
jtfInput = new JTextField(10);
jtfInput.addMouseListener(pmml);
jtaOutput = new JTextArea(10, 10);
jtaOutput.addMouseListener(pmml);
P1.add(jtfInput);
P1.add(jtaOutput);
getContentPane().add(P1, BorderLayout.CENTER);

} // end init()
**** END CODE ******
**** POPUP CODE ****

import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.event.*;
import javax.swing.*;
//import javax.swing.event.*;
import javax.swing.text.*;
public class PopupMenuMouseListener extends MouseAdapter
{
private JPopupMenu popup = new JPopupMenu();
private JMenuItem undoItem, cutItem, copyItem, pasteItem, deleteItem, selectAllItem;
private JTextComponent textComponent;
String savedstring="";
String lastactionselected="";

public PopupMenuMouseListener()
{
Action action = new AbstractAction("Undo")
{
public void actionPerformed(ActionEvent ae)
{
if(lastactionselected.compareTo("")!=0)
{
textComponent.setText("");
textComponent.replaceSelection(savedstring);
}
}
};
undoItem = popup.add(action);
undoItem.setMnemonic('t');
popup.addSeparator();
action = new AbstractAction("Cut")
{
public void actionPerformed(ActionEvent ae)
{
lastactionselected="c";
savedstring=textComponent.getText();
textComponent.cut();
}
};
cutItem = popup.add(action);
cutItem.setMnemonic('t');
action = new AbstractAction("Copy")
{
public void actionPerformed(ActionEvent ae)
{
lastactionselected="";
textComponent.copy();
}
};
copyItem = popup.add(action);
copyItem.setMnemonic('c');
action = new AbstractAction("Paste")
{
public void actionPerformed(ActionEvent ae)
{
lastactionselected="p";
savedstring=textComponent.getText();
System.out.println("in paste code savedstring is: "+savedstring);
textComponent.paste();
}
};
pasteItem = popup.add(action);
pasteItem.setMnemonic('p');
action = new AbstractAction("Delete")
{
public void actionPerformed(ActionEvent ae)
{
lastactionselected="d";
savedstring=textComponent.getText();
textComponent.replaceSelection("");
}
};
deleteItem = popup.add(action);
deleteItem.setMnemonic('d');
popup.addSeparator();
action = new AbstractAction("Select All")
{
public void actionPerformed(ActionEvent ae)
{
lastactionselected="s";
savedstring=textComponent.getText();
textComponent.selectAll();
}
};
selectAllItem = popup.add(action);
selectAllItem.setMnemonic('a');
}
public void mouseClicked(MouseEvent e)
{
//if (e.getModifiers()==InputEvent.BUTTON3_MASK)
if(SwingUtilities.isRightMouseButton(e))
{
if (!(e.getSource() instanceof JTextComponent))
{
return;
}
textComponent = (JTextComponent)e.getSource();
// 1.3 version
//textComponent.requestFocus();
// 1.4 preferred method
textComponent.requestFocus();
//textComponent.requestDefaultFocus();
//textComponent.requestFocusInWindow();

boolean enabled = textComponent.isEnabled();
boolean editable = textComponent.isEditable();
boolean nonempty = !(textComponent.getText()==null || textComponent.getText().equals(""));
boolean marked = textComponent.getSelectedText()!=null;
boolean pasteAvailable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).isDataFlavorSupported(DataFlavor.stringFlavor);
undoItem.setEnabled(enabled && editable);
cutItem.setEnabled(enabled && editable && marked);
copyItem.setEnabled(enabled && marked);
pasteItem.setEnabled(enabled && editable && pasteAvailable);
deleteItem.setEnabled(enabled && editable && marked);
selectAllItem.setEnabled(enabled && nonempty);
popup.show(e.getComponent(),e.getX(), e.getY());
}
}
} // end PopupMenuMouseListener

*** END POPUP CODE *****
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8718
    
    6

Applets run inside a "sandbox", where they cannot access resources on the client computer. This error:

indicates that you have tried to get outside the sandbox and the JVM security stopped you. You need to either 1. not do that or 2. digitally sign the applet. If you want to know more about #2, search this forum. It comes up a few times a week.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Al Murphy Al Murphy
Greenhorn

Joined: Feb 03, 2004
Posts: 16
Joe,
Yes I see now the line:
boolean pasteAvailable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).isDataFlavorSupported(DataFlavor.stringFlavor);

tries to access the default clipboard - which according to yourself is not allowed. Problems is though what alternative can I use with an applet. does swing comes with a clipboard??
Al.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java RMC popup applet error
 
Similar Threads
[newbie] Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
Where dose JSException come from?
JButton Problem
JButton Action Listener Problem