aspose file tools*
The moose likes Applets and the fly likes Accesing system clipboard in Applet    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Accesing system clipboard in Applet    " Watch "Accesing system clipboard in Applet    " New topic
Author

Accesing system clipboard in Applet

Rajiv Karambalkar
Greenhorn

Joined: Dec 06, 2006
Posts: 2
have designed a applet where i have created my own buttons . cut, copy and paste. and have used javax.swing.text.DefaultEditorKit
DefaultEditorKit.cutAction,DefaultEditorKit.copyActionDefaultEditorKit.pasteAction action classes to access system's clipboard.

For the first time when it loads at the client side(in Browser) , applet is not able to access the system clipboard, but when i start that same applet after closing it , it can able to
access the system's clipboard. I mean , for first time, i can not paste data from external application like notepad, but for next time onwards, i can paste the data copied from Notepad.

Can anybody help me out to find , why its not happening for the first time.
Rajiv Karambalkar
Greenhorn

Joined: Dec 06, 2006
Posts: 2
I have written following code.
package com.applet;
import java.applet.Applet;
import java.util.Hashtable;
import javax.swing.Action;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.text.DefaultEditorKit;

public class ClipBoard extends Applet {
JTextField textField = null;
Action actions[] = null;
JButton cutButton = null;
JButton copyButton = null;
JButton pasteButton = null;

public void init() {
textField = new JTextField(20);
add(textField);
actions = textField.getActions();
Action cutAction = findAction(actions, DefaultEditorKit.cutAction);
Action copyAction = findAction(actions, DefaultEditorKit.copyAction);
Action pasteAction = findAction(actions, DefaultEditorKit.pasteAction);

cutButton = new JButton(cutAction);
cutButton.setText("Cut");
add(cutButton);

copyButton = new JButton(copyAction);
copyButton.setText("Copy");
add(copyButton);

pasteButton = new JButton(pasteAction);
pasteButton.setText("Paste");
add(pasteButton);
}

public static Action findAction(Action actions[], String key) {
Hashtable<Object, Action> commands = new Hashtable<Object, Action>();
for (int i = 0; i < actions.length; i++) {
Action action = actions[i];
commands.put(action.getValue(Action.NAME), action);
}
return commands.get(key);
}
}
-----------------------------------ClipBoard.html-------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head><body>
<APPLET CODE="com.applet.ClipBoard.class" WIDTH=460 HEIGHT=160></APPLET>
</body>
</html>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accesing system clipboard in Applet