Writing on system clipboard from an applet.

Is it possible?
I have tried to write on it but an exception is occoured:
java.security.AccessControlException: access denied (java.awt.AWTPermission accessClipboard)
The code that I have used is:
import java.security.*;
import java.awt.*;
import java.awt.datatransfer.*;
import javax.swing.*;
public class Blah extends JApplet {
public void init() {
String exampleStr = "Hi!";
Clipboard clipboard;
Transferable trans;
StringSelection strSelect;
try {
SecurityManager security = System.getSecurityManager();
if (security != null)
security.checkSystemClipboardAccess();
clipboard=Toolkit.getDefaultToolkit().getSystemClipboard();
strSelect = new StringSelection(exampleStr);
trans = (Transferable)strSelect;
clipboard.setContents(trans, strSelect);
System.out.println("Clipboard copy successful");
catch (Exception e) {
System.err.println("Clipboard copy failed");
System.err.println(e);
Thanks

First, your applet must be signed to access the system clipboard. And on Netscape 4.7.x, you need to enable the privilege from within the same method where you get the system clipboard. On IE 5.5/6.0, signing the applet is all that is necessary.
Here's what I do on Netscape:
Make sure when you call "PrivilegeManager.enablePrivilege("UniversalSystemClipboardAccess");", that you get the system clipboard within the same method. Failure to do this will cause a ForbiddenTargetException.
My code looks like:
public java.awt.datatransfer.Clipboard getSystemClipboard()
java.awt.datatransfer.Clipboard clipboard = null;
try
PrivilegeManager.enablePrivilege("UniversalSystemClipboardAccess");
clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
PrivilegeManager.revertPrivilege("UniversalSystemClipboardAccess");
catch (netscape.security.ForbiddenTargetException se)
se.printStackTrace();
catch(Exception e)
e.printStackTrace();
return clipboard;
This works successfully on Netscape 4.7.8. On IE 5.5/6.0, I didn't have to do anything other than having a signed applet to get the system clipboard. With the code above, I also am using a signed applet.
Hope this helps anyone else trying to make this work.
-Dave.

Similar Messages

  • Reading System Spec from an Applet

    Hi guys.
    Can some applet expert tell me what System spec is available to a signed applet to read?
    I'm after stuff like amount of physical memory, free HDD space, cpur speed, gfx card etc - the type of stuff you get from DXDiag. I know the majority of it is not available. I was just wondering what was.
    Thanks.

    Yes, it's possible. Use this:
            Runtime r = Runtime.getRuntime ();
            Process p = r.exec ( command );++ read the help and use http://www.google.com for more informations.

  • System clipboard

    How can i access or grant access to the system clipboard to an applet ???

    Clipboard c = getToolkit().getSystemClipboard();

  • Signed Applet JTextField copy to system clipboard

    Hi all,
    We have a signed and deployed our JAR file that contains our applet following the instructions listed at:
    http://java.sun.com/products/plugin/1.3/docs/rsa_signing.html
    We used Thwate as our CA. All seemed good.
    However any JTextFields that are in our applet cannot access the system clip board. Looking at the source for JTextComponent it should have access to the system clipboard if the securitymanager allows it.
    The strange thing is that if I call getToolkit().getSystemClipboard() from our applets I can access the clipboard and copy to the system clipboard. Even the code in JTextComponent that checks for system clipboard access (canAccessSystemClipboard) works fine when pasted into the applet.
    Why cant a JTextField copy to the clipboard? Has anyone else come across this?

    Juste an idea.... Is your JTextField belonging to the javax.swing.... packages ?
    Or did you compile using some com.ms , ibm.... sun... package ? This could lead to some different implementations.

  • Applet access to system Clipboard

    Hi all:
    I am creating a customized version of the mud telnet application for a customer. They have requested cut/paste functionality and I have been able to provide this capability. The problem is the applet cannot get access to the system clipboard so all cut/paste functions can only occur within the applet. I am able to access the system clipboard by creating a java.policy file and setting a permission. The problem is that most of the workstations, and a good number that will be using home computers running Win 98. They don't want the users to have to download the new JRE from Sun (although I know this works). I am looking for a way to creat a JAR file using the old JDK 1.1 (or the current toolkit if it is possible) that will allow access from the Applet to the System Clipboard. I have search the web for an answer, with no success. Can anyone give me any suggestions?
    Anybody had to do the same thing before?
    Thanks.
    John Kreiner

    I know this is an old thread, but I thought I would answer it.
    To access the clipboard via an applet, you need to use JavaScript.
    The first thing to do is to create a class that uses reflection to use the JSObject. The reason why reflection is used is because it is a pain (ITA) to specify a compatible binary for eacy java version (e.g. java40.jar, plugin.jar, jaws.jar, etc). Here is the class:
    import java.lang.reflect.*;
    import java.applet.Applet;
    public class JavaScript {
         public static void call(Applet applet, String methodName, Object[] param) {
              try {
                   Class js = Class.forName("netscape.javascript.JSObject");
                   Method callMethod = js.getMethod("call", new Class[] { String.class, Object[].class });
                   callMethod.invoke(getWindow(applet), new Object[] { methodName, param});
              } catch (Throwable t) {}
         public static Object getWindow(Applet applet) {
              Object o = null;
              try {
                   Class js = Class.forName("netscape.javascript.JSObject");
                   Method getWindowMethod = js.getMethod("getWindow", new Class[] { Applet.class });
                   o = getWindowMethod.invoke(null, new Object[] { applet });
              } catch (Throwable t) {}
              return o;
    }Now, when you want to copy something to the clipboard, you will do:
    JavaScript.call(someApplet, "copyToClipboard", text);
    BUT the "copyToClipboard" function has not been defined yet. This will be a JavaScript function in the html:
    <script language="JavaScript1.1">
    function copyToClipboard(text) {
         document.myForm.myInput.value = text;
         var rng = document.myForm.myInput.createTextRange();
         rng.execCommand("RemoveFormat");
         rng.execCommand("Copy");
    </script>And one last thing is that a JavaScript text component is required in order to create the "rng" variable. To do this, use a hidden field in the html:
    <form name="myForm">
         <input name="myInput" type="hidden">
         </input>
    </form>

  • Writing to the System clipboard

    This company uses LabVIEW 2012 and LabWindows 2010 in an Aerospace environment. The use of older versions is done to have commonality with their facilities across the globe. Thus, I cannot get them to upgrade.
    On their new test station, they have 14 serial ports to communicate with the unit under test. I have developed a LabVIEW serial port interface program that will allow them to communicate with those serial ports. I have the ini file configured to allow the user to run multiple instances of the executable, for as many ports as they desire, during their testing. One option that they requested is the ability to right click the mouse, have a menu display to select copy or copy all of the data to the clipboard so that they can paste the received data into a test report. I used the LabVIEW App Invoke Node function Write to Clipboard and Read From Clipboard to perform the task. However, I have the issue that this works on some instances and does not work on other instances of the executables. Since the code is the same, the user enters which port to connect to, I do not understand why I have this issue. It works fine on my PC which only has a single COM port.
    I decided to write two LabWindows functions to read and write to the clipboard using ClipboardGetText and ClipboardPutText. I call those dll functions from LabVIEW. The first call to the function ClipboardPutText works in the sense that the data is placed into the clipboard. However, I immediately get a fatal error and the process stops. (I did not save a screen image and the test stations are in use at this time). After that, none of the other instances will copy the data and they all result in a fatal error and stop. This is repeatable as I restarted the software numerous times as I tried to determine the cause.
    Since I do not have access to the code for the clipboard functions, I cannot determine if I need to configure something else related to the clipboard or the process attempting to read/write from/to the clipboard. I will continue to search but wanted to ask the experts in control of the clipboard software to determine if they have any recommendations on what may need to be added.
    For LabWindows, the only other call that I performed was a free command after I executed the ClipboardGetText, if the pointer to the text was not NULL.
    I will post this in both the LabVIEW and LabWindows discussion boards in case one or the other has a solution.
    Thank you for your help.
    I can provide a zip file, containing the source code, to NI personnel if you provide an email address. Since I am a contractor, I am not sure if the company’s policy allows global posting of their code, although I may be able to reduce the code to a minimum example, if necessary.

    I have done more testing in an attempt to clarify the error condition. I upgraded to LabVIEW 2014 on a Windows 7 SP1 system. I have enclosed some screen shots to show what I am doing.
    My software allows multiple copies, 14 in this case, versions of the executable to run at one time. The software controls serial ports. The enclosed image of the front panel, LabVIEW window.png, indicates the COM port, baud rate, and version at the top of the window. This first small control allows the user to enter a command to send to the port. The large bottom indicator displays the data received on the port. I have menu items, pressing the right mouse button, that allows the user to clear all of the data, copy selected data, or copy all data. I have enclosed images of the copy, copy all, write to clipboard, and read serial port parts of the code. I was only copying small amounts of data, perhaps less than 256 bytes.
    Here’s what I have noticed:
    If I execute the code on my desktop computer, only 1 COM port, everything works fine. The copy and copy all will place the data into the system clipboard which allows the pasting of the data into Notepad.
    If I execute the code on the test station, opening all 14 ports, we are using the NI serial card for all of the additional ports, the code works fine, as in item 1, for a couple of the executables but not the rest.
    If I select a subset of the data being displayed, highlighted in blue by LabVIEW, then right click the mouse selecting the copy, the blue highlighting goes away but the data is copied to the clipboard allowing me to paste into Notepad.
    If I right click the mouse selecting copy all, the data is NOT copied to the system clipboard so that I cannot paste it into Notepad.
    In the Write to Clipboard function, I write to the clipboard and then read the clipboard. I added code to display, in a popup window, what was written to the clipboard and what was read from the clipboard. The data was the same although the data was not on the system clipboard so that I could paste it into Notepad.
    I tried to select a subset of the data being displayed and then right clicking the mouse to do a copy all to see if that made a difference. It did not.
    I tried to make the Write to Clipboard function re-entrant to test that theory. Not change in the behavior.
    At one point, I tried to use LabWindows. I used the LabWindows clipboard calls and then tried calling the Microsoft clipboard functions directly. While those functions worked in LabWindows without a problem, I would get executable crashes when I tried to call my LabWindows functions from LabVIEW. If I commented out the actually code part, the call to the functions would return without crashing the executable. The issue was not in how the LabWindows functions were being called but something in the clipboard calls themselves. So, I decided that making a call using LabWindows offered nothing that I could use. I returned to using only LabVIEW and updated to 2014 to determine if that might solve the issue. No luck so far.I do not understand why, when I call the LabVIEW function to write to the clipboard, that it does not work for every executable of the multiple instances. Is there some other function that needs to be called prior to writing to the clipboard due to having multiple instances? Why does selecting a subset work when I do the copy but not when I copy all. If I am passing the data to write to the clipboard, why does selecting a subset and the copying only that subset work but the copy all does not? I do not understand how LabVIEW handles multiple instances and is they are truly considered separate processes.
    I seldom use these forums as I can get most of the code that I write to work as expected. Thank you for all of your help and suggestions.
    Attachments:
    LabVIEW window.png ‏25 KB
    Copy Menu Item.png ‏39 KB
    Copy ALL Menu Item.png ‏33 KB

  • How to writing an image from my applet to my apache webserver

    hi everyone,
    i have a big problem, writing an image from my applet to my apache
    webserver. i tried three way's of writing that file. every way was
    described in forums to solve this problem, but non of them worked and
    i don't know why. i'll give you the code of my writing-methods and
    describe, what happen when i test them, in order someone of you can
    give me an usefull tip, where the problem is.
    as inputparameter i give my method a new URL referring to
    http://localhost/test.jpg (this is the same directory, where my applet
    is loaded from, so i should have reading and writing permission,
    havn't i? while i'm developing, my applet runs on the same pc as my
    webserver, just in case you're wondering about localhost) and a
    selfmade BufferedImage (i already testet if it is not null and shows
    the correct things ... all ok).
    1. try:
    private void writeImageToServer(URL fileURL,BufferedImage img){
    try {
    URLConnection urlConnection = fileURL.openConnection();
    urlConnection.setDoOutput(true);
    OutputStream urlout = urlConnection.getOutputStream();
    BufferedOutputStream out = new BufferedOutputStream(urlout);
    ImageIO.write(img,"jpg",out);
    out.close(); // i also tried without this line -> same result
    // additionally a question: do i need
    out.close()?
    catch( IOException e ){
    e.printStackTrace();
    result:
    test.jpg doesn't appear in the webroot. but some very strange messages
    in the error.log of my apacheserver:
    [Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not
    exist: c:/programme/apache
    group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageOutputStreamSpi
    [Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not
    exist: c:/programme/apache
    group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageReaderSpi
    [Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not
    exist: c:/programme/apache
    group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageInputStreamSpi
    [Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not
    exist: c:/programme/apache
    group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageWriterSpi
    [Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not
    exist: c:/programme/apache
    group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageTranscoderSpi
    i cannot explain this lines to myself, because my apache should have
    nothing to do with java. all my javacode is executed on the client
    side in the browser. do this messages mean i have to add the ImageIO
    package from the sdk to my jar-applet. the jre, used by my iexplorer,
    doesn't contain this files in the meta-inf/services directory of
    rt.jar, but that's version 1.4.2_03, the same as my sdk, and the
    rt.jar contains the corresponding classfiles at javax.imageio.spi. so
    i'm realy confused by this messages.
    2. try:
    private void writeImageToServer(URL fileURL,BufferedImage img){
    try {
    URLConnection urlConnection = fileURL.openConnection();
    urlConnection.setDoOutput(true);
    OutputStream urlout = urlConnection.getOutputStream();
    BufferedOutputStream out = new BufferedOutputStream(urlout);
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    encoder.encode(img);
    out.close(); // same comments as above
    catch( IOException e ){
    e.printStackTrace();
    result:
    nothing. no error-messages in the error.log, no exceptions in the
    java-console and no test.jpg in the webroot. i searched my whole
    harddrives for it: nothing. isn't this the way, the JPEGImageEncoder
    works?
    3. try:
    private void writeImageToServer(URL fileURL,BufferedImage img){
    try {
    File file = new File(fileURL.toString);
    file.createNewFile();
    BufferedOutputStream out = new BufferedOutputStream(new
    FileOutputStream(file));
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    encoder.encode(img);
    out.close(); // same comments as above
    catch( Exception e ){
    e.printStackTrace();
    result:
    the SecurityManager denies this action with "access denied" while
    calling createNewFile(). well, this way was dedicated to run from an
    application, not from an applet. i'd have to sign my applet to get the
    rights to do this, or i can edit java.policy on my client, what i
    don't want, because i cannot do this on every client, the applet will
    run, when i'm finished with it. this brings me to the question: does
    anybody know's how to sign my applet and give it full access to the
    harddrive and the webserver without paying 400$ to VeriSign for a
    commercial CA? i want to do this by myself, without paying anything
    and without giving a lot of information to another company.
    i would realy appreciate, if someone could give me a hint where i am
    wrong or how to do this correct.
    thank you very much
    [email protected]

    You hold several misconceptions. The first is that an applet can write to a server without help from the server. That will never work on a real server (though it might work in testing, if the server is on the same PC as the applet). Applets cannot get a File object that points to any place on the server.
    If you write a servlet designed for accepting image uploads, the applet can communicate back to that servlet and feed it the bytes of the image. There are other technologies that can replace the servlet, of course (PHP, ASP..) but I mention that because you say you are running Apache - and that is very Java oriented.
    For more help on servlets, try the [Web Tier APIs - Java Servlet|http://forums.sun.com/forum.jspa?forumID=33] forum.

  • Problems copying from PJC to system clipboard

    I am working on a PJC to allow for editing of large text fields (> 64K). I have most of the functionality working fine. However, I am having a problem using cut, copy, and paste.
    Some details, the PJC extends VBean and includes as JTextArea. Our users want a right click menu to provide functionality for cutting, copying, pasting, and spell checking. I was able to get the spell check working using JSpell. I am not able to get the menu entries for cut, copy, and paste to work. I construct a JPopMenu with the appropriate items. When the menu is activated, if the user selects cut, the actionPerformed method executed the cut method of the JTextArea. This does cut the text from the item, however it is not added to the clipboard for use in other items, except those that have the same implementation class of the original item. If the user uses the keyboard (CTRL-X, CTRL-C, or CTRL-V) the selected data is copied to the system clipboard
    Here is the method I used to create the menu items:
      private JMenuItem makeMenuItem(String label, char acceleratorKey)
        JMenuItem item = new JMenuItem(label);
        item.addActionListener(this);
        item.setMnemonic(acceleratorKey);
        item.addKeyListener(this);
        printDebugMessage("Horizontal text alignment = " + item.getHorizontalAlignment());
        item.setHorizontalAlignment(SwingConstants.LEFT);
        printDebugMessage("Horizontal text alignment = " + item.getHorizontalAlignment());
        return item;
      }Here is the actionPerformed method:
      public void actionPerformed(ActionEvent ae)
        String selection = ae.getActionCommand();
        if (selection.equals("Cut"))
          printDebugMessage("Cut selected");
          text.cut();
        else if (selection.equals("Copy"))
          printDebugMessage("Copy selected");
          text.copy();
        else if (selection.equals("Paste"))
          printDebugMessage("Paste selected");
          text.paste();
        else if (selection.equals("Spell Check"))
          printDebugMessage("Spell Check selected");
          doSpellCheck();
      }I read that jar files needed to be signed to interact with the desktop, but when I signed the jar file the results were the same.
    Platform
    10g AS on Solaris 10.1.2.2
    Windows XP (SP2)
    IE7
    Sun plugin 1.5.0_11 (problem also occurs with 1.4.2_06)
    Any insights would be helpful.
    Thanks

    will that create a problem?Try it and see.

  • Writing new HTML to a page from an applet using LiveConnect, 1.3.1 Plug-i

    Has anyone been able to successfully replace a page with an applet with the dynamically generated HTML from an applet using LiveConnect and Plugin 1.3.1 in Netscape 6.2 or IE?
    The following works fine without plugin or with 1.4.0 beta3 plugin.
    Here is the code that I use without plugin:
    JSObject windowObject = JSObject.getWindow(this);
    JSObject documentObject = (JSObject) windowObject.getMember("document");
    documentObject.call("close",null);
    documentObject.call("open",null);
    String anArray1[] = {null};
    anArray1[0] ="some HTML here";
    documentObject.call("write", anArray1);
    documentObject.call("close",null);
    Here is the code that I use with 1.4.0 plugin:
    JSObject windowObject = JSObject.getWindow(this);
    JSObject documentObject = (JSObject) windowObject.getMember("document");
    String anArray1[] = {null};
    anArray1[0] ="some HTML here";
    documentObject.call("write", anArray1);
    When I try to use anyone of the above using plugin 1.3.1, the browser either hangs or plugin generates runtime error. What is the correct way of writing to a document object? Or what is the way that works for 1.3.1 plugin?

    Hi,
    I am doing this in my applet to replace the page containing the applet with the new content. I tested that extensively with Netscape 4.7 and IE 5.5+. Definitely works if you are using Java Plug-In 1.3.1_02. Does not work well in Netscape 6.2.
        protected void setPageContent(final String newContent) {
            final JSObject window = JSObject.getWindow(this);
            final JSObject document = (JSObject) window.getMember("document");
            new Thread( new Runnable() {
                            public void run() {
                                document.call("clear", null);
                                document.call("write", new String[]{newContent});
                                try {
                                              document.call("close", null);
                                   } catch (JSException ignored) {
                        } ).start();

  • Paste from System Clipboard

    Hi,
    I've been looking all over on how to copy and paste to/from the system clipboard. I've used the tutorial classes at http://java.sun.com/developer/technicalArticles/releases/data/ explaining new data transfer capabilities in java, and it seems that I can copy and paste to/from a java application but I can't seem to paste images from the system clipboard in applications such as Thunderbird and OpenOffice.
    I'm not sure what the problem or solution is, but if anyone has any ideas that would be great. I was thinking it may be that in the tutorial it is copying the content of a JComponent to the system clipboard but I'm pretty sure that is not it.
    Any help is appreciated.
    thanks

    import java.awt.*;
    import java.awt.datatransfer.*;
    public class ClipboardImage
          *  Retrieve an image from the system clipboard.
          *  @return     the image from the clipboard or null if no image is found
         public static Image read()
              Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents( null );
            try
                if (t != null && t.isDataFlavorSupported(DataFlavor.imageFlavor))
                    Image image = (Image)t.getTransferData(DataFlavor.imageFlavor);
                    return image;
            catch (Exception e) {}
            return null;
          *  Place an image on the system clipboard.
          *  @param  image - the image to be added to the system clipboard
         public static void write(Image image)
            if (image == null)
                throw new IllegalArgumentException ("Image can't be null");
              ImageTransferable transferable = new ImageTransferable( image );
            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(transferable, null);
        static class ImageTransferable implements Transferable
            private Image image;
            public ImageTransferable (Image image)
                this.image = image;
            public Object getTransferData(DataFlavor flavor)
                 throws UnsupportedFlavorException
                if (isDataFlavorSupported(flavor))
                     return image;
                else
                    throw new UnsupportedFlavorException(flavor);
            public boolean isDataFlavorSupported (DataFlavor flavor)
                  return flavor == DataFlavor.imageFlavor;
            public DataFlavor[] getTransferDataFlavors ()
                return new DataFlavor[] { DataFlavor.imageFlavor };
         public static void main(String[] args)
              Image image = Toolkit.getDefaultToolkit ().createImage("???.jpg");
              ClipboardImage.write( image );
              javax.swing.ImageIcon icon = new javax.swing.ImageIcon( ClipboardImage.read() );
              javax.swing.JLabel label = new javax.swing.JLabel( icon );
              javax.swing.JFrame frame = new javax.swing.JFrame();
              frame.setDefaultCloseOperation( javax.swing.JFrame.EXIT_ON_CLOSE );
              frame.getContentPane().add( label );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }

  • Calling System.exit(0) from an applet

    Hello,
    I have a weird problem.
    First... my applet has full permissions in the java.policy file.
    problem:
    When I call System.exit(0) from the applet (jbutton's action listener), the applet disappears from the browser window and the browser freezes.
    but
    if I display a messagedialog (JoptionPane) before calling System.exit(0) ... everything works fine (after I press ok on the message dialog, the browser window disappears)
    here's my code
    <CODE>
    public class testApp extends JApplet{
    public void init(){
    System.err.println("hello");
    JButton button = new JButton("Exit");
    button.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    JOptionPane.showMessageDialog(new JFrame(),"Exiting...");
    System.exit(0);
    this.getContentPane().add(button);
    </CODE>
    what am I missing?

    an applet has security restrictions that forbids it from accessing a client file system. BUT there are ways like signing your applet or just asking the user to change the security setting when he calls the applet.
    This link shows the steps involved in signing an applet very clearly. :-http://developer.java.sun.com/developer/technicalArticles/Security/Signed/
    Or the user(client) can go to the "Internet Option" under the Tools of the web browser(IE). Go to security and change to custom security for the Internet.(Caution the user needs to return the security to default after finishing accessing the applet). Click to "Custom Java Setting" button. If you don't see a "Custom Java Setting" button below then scroll down to "Java Permissions" option and select custom. Now you will see the "Custom Java Setting" button. Go there and select "edit permission" tab. Under "Unsigned Content" select enable. This will grant full permission.

  • Reading and writing to a text file from an Applet

    I'm a novice java programming with very little formal programming training. I've pieced together enough knowledge to do what I've wanted to do so far...
    However, I've been unable to figure out how to read and write to a text file from an Applet (I can do it from a normal java program just fine). Here is a simple example of what I'd like to do (you can also look at it on my website: www.stat.colostate.edu/~leach/test02/test02.html). I know that there is some problem with permission/security but I'm not smart enough to understand what the error messages are telling or understand the few books I have. If anyone can tell me how to get this applet to work, or direct me to some referrences that would help me out I'd really appreciate it.
    Thanks,
    Andy
    import java.applet.Applet;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    public class test02 extends Applet {
    public Button B_go;
    public GridBagConstraints c;
    public void init() {
    this.setLayout(new GridBagLayout());
    c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    B_go = new Button("GO");
    c.gridx=1; c.gridy=0; c.gridwidth=1; c.gridheight=1;
    c.weightx = c.weighty = 0.0;
    B_go.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    print_stuff();
    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    this.add(B_go,c);
    public static void print_stuff() {
    try{
    File f = new File("test02.txt");
    PrintWriter out = new PrintWriter(new FileWriter(f));
    out.print("This is test02.txt");
    out.close();
    }catch(IOException e){**/}
    }

    I have almost the exact same problem, and I am in the same situation as you are with respects to the language.
    I am simply trying to create a file and output some garbage to it but my applet always spits back a security violation. I've tried eliminating the restrictions on the applet runner I use but I still get the error.
    My method:
    debug = new Label() ;
    debug.setLocation( 20, 20 ) ;
    debug.setSize( 500, 15 ) ;
    add( debug ) ;
    // output
    try
         OutputStream file = new FileOutputStream( new File( "" + getCodeBase() + "output.txt" ) ) ;
         byte[] buffer = { 1, 2, 3, 4, 5 } ;
         file.write( buffer ) ;
         file.close() ;
    } catch( Exception e )
         debug.setText( e.toString() ) ;
         Can anyone tell why this isnt working?

  • High performance writing Chinese from an Applet to a Servlet

    Hi,
    I am using DataOutput/InputStreams to wrtie UTF (Chinese Characters from an Applet to a servlet) Now, I already HAVE the chinese characters in the applets memory and I need to write them to the servlet. I am using the "writeUTF()" and "readUTF" methods in the Input and output Streams. Now I want to replace the Data Streams with buffered Streams to improve performance. What is the equivalent method for buffereed Streams?
    DataOutputStream output = new DataOutputStream(connection.getOutputStream());
    output.writeUTF(chineseString);
    output.close();
    DataInputStream input = new DataInputStream(connection.getInputStream());
    String response = input.readUTF();
    input.close();
    Thanks.
    Regards,
    Carlos

    Hi Carlos,
    I don't think there is a method for buffered streams that is exactly equivalent to writeUTF, but you could use the character stream reader/writer pair as follows:
    OutputStreamWriter osw = new  OutputStreamWriter(connection.getOutputStream (), "UTF8");
    Writer output = new BufferedWriter(osw);     
    InputStreamReader  isr = new InputStreamReader(connection.getInputStream (), "UTF8");
    Reader input = new BufferedReader(isr);     now, however, since these classes don't have a read/write String method you will need to write out your string character by character followed by an end of Line:
    loop through characters in output String:
         output.write(aChar)
    output.newline ()and then read it back in as a line using:
    input.readLine() Post back if it's unclear.
    Regards,
    Joe

  • Accessing the clipboard in an Applet?

    Hello.
    I'm currently trying to allow copy & paste in an applet (extends JApplet). I'd like it to be able to paste in text from other sources (Notepad, websites, etc.) when the user right-clicks the mouse, and for this, it seems I need to use the system clipboard. However, I get an AccessControlException: access denied error; apparently it won't let applets access the system clipboard.
    Does anyone know of a workaround?

    Sign the applet.

  • Programatically copy to  System Clipboard

    I'm trying to programatically copy a value from my applet to the system clipboard without much luck. My jars have all been signed and I am able to ctrl-c and ctrl-v to/from the applet/system clipboard. What I need to be able to do is invoke this behaviour from a popup menu. Below is a code snippet:
    public void actionPerformed(ActionEvent event)
                   Object source  = event.getSource();
                   String strValue = source.toString();
                   StringSelection strSelection = new StringSelection(strValue);
                   Toolkit.getDefaultToolkit().getSystemClipboard().setContents( strSelection , strSelection );
                    // at this point I have verified that 't' does indeed contain my item.
                   Transferable t =Toolkit.getDefaultToolkit().getSystemClipboard().getContents(strSelection );
    }When I try to paste into, say notepad, there does not appear to be anything in the clipboard.
    Any idea as to what I'm doing wrong? I'm using 1.5 plugin (but want to move down to 1.4)
    Thanks,
    -Craig Green

    I guess you didn't sign it right or called your method from untrusted (unsigned) code.
    for signing:
    http://forum.java.sun.com/thread.jsp?forum=63&thread=524815
    second post
    for a full trace:
    To turn the full trace on (windows) you can start the java console, to be found here:
    C:\Program Files\Java\j2re1.4...\bin\jpicpl32.exe
    In the advanced tab you can fill in something for runtime parameters fill in this:
    -Djavaplugin.trace=true -Djavaplugin.trace.option=basic|net|security|ext|liveconnect
    if you cannot start the java console check here:
    C:\Documents and Settings\userName\Application Data\Sun\Java\Deployment\deployment.properties
    I think for linux this is somewhere in youruserdir/java (hidden directory)
    add or change the following line:
    javaplugin.jre.params=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
    for 1.5:
    deployment.javapi.jre.1.5.0.args=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
    The trace is here:
    C:\Documents and Settings\your user\Application Data\Sun\Java\Deployment\log\plugin...log
    I think for linux this is somewhere in youruserdir/java (hidden directory)

Maybe you are looking for

  • How do I use the vector web forms??

    I'm new to using vector graphics and need to know how to go about using these web forms using Illistrator to make it functional on a web site. I tried opening it with the Illustrator, Fireworks, but not sure how to get the white fields to actually wo

  • I am trying to find out if I can upgrade my old airport express from WEP to WPA2?  If so, how do I do that?

    I am trying to find out if my old Airport Express can be upgraded from WEP to WPA2?  If so, does anyone know how to do this?  I have a new PC for work reasons and I cannot get online with my WEP password.  I realize now this is why my family and frie

  • File name from a path

    hi , there is a path "c:\abc\abc\abc\abc\abc.doc", i have to get file name from it. but i had to write a dynamic code which can get the file name from any given path.

  • Problem in copy a string to a message parameter

    Hi all, I have a problem in copy a static string into a message as its parameter. I use the default function in creating the copy rules... <copy xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/">      <from expression="string(WS1-PSC4-K

  • Latest kernel crash while installing on a Compaq Proliant ML370G2

    SunOS Release 5.8 Version Generic_108529-13 32-bit Copyright 1983-2001 Sun Microsystems, Inc. All rights reserved. panic[cpu0]/thread=fec17660: BAD TRAP: type=0 (Divide Error Exception) rp=fec12b70 addr=0 Divide Error Exception pid=0, pc=0xfea6b5ef,