• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accesing system clipboard in Applet

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic