Results 1 to 7 of 7
Like Tree2Likes
  • 2 Post By Tolls

Thread: java help.. pasting from you java written program into another window?

  1. #1
    delete123 is offline Member
    Join Date
    Jul 2012
    Posts
    4
    Rep Power
    0

    Question java help.. pasting from you java written program into another window?

    hey, i have this program which runs the NOTEPAD program and then pastes some string (text) that i stored inside it , into the notepad window:

    Java Code:
    Java Code:
    import java.io.File;
    import java.io.FileWriter;
    import javax.swing.JTextField;
    
     public class PasteToNotepad {
    
       public static void main(String[] args) throws Exception {
         String text = "Some text for testing.";
         JTextField textField = new JTextField(text);
         textField.setSelectionStart(0);
         textField.setSelectionEnd(text.length() - 1);
         textField.copy();
    
         String vbs = ""
                 + "Set WshShell = WScript.CreateObject(\"WScript.Shell\")\n"
                 + "WshShell.Run \"notepad\", 9\n"
                 + "WScript.Sleep 500\n"
                 + "WshShell.SendKeys \"^V\"";
    
         File file = File.createTempFile("PrintDialog", ".vbs");
         file.deleteOnExit();
         FileWriter fw = new java.io.FileWriter(file);
         fw.write(vbs);
         fw.close();
         Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
         p.waitFor();
       }
     }
    NOW ALL I NEED IS JUST A SIMPLE THING , IF THIS JAVA CODE RUNS THE notepad THEN HOW CAN I RUN ANY OTHER PROGRAM NOT THE notepad, WHERE SHOULD I SET THE DIRECTORY IN THIS CODE, PLEASE INFORM ME....
    Last edited by Fubarable; 07-23-2012 at 12:47 AM. Reason: code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: java help.. pasting from you java written program into another window?

    I've re-formatted your question so that it's readable. Darryl already told you all this previously, and his recommendations are still valid. Please listen to them.

    As to your question, you "run" an outside program using a Process, similar to the code above, but using a String that is similar to a String that would allow you to run the program from the command line in your current OS/platform. Current recommendation is to use a ProcessBuilder for this. You can learn how to use this from the ProcessBuilder API which I've linked to. You're going to have to experiment some and then let us know what happens.

  3. #3
    delete123 is offline Member
    Join Date
    Jul 2012
    Posts
    4
    Rep Power
    0

    Default Re: java help.. pasting from you java written program into another window?

    Quote Originally Posted by Fubarable View Post
    I've re-formatted your question so that it's readable. Darryl already told you all this previously, and his recommendations are still valid. Please listen to them.

    As to your question, you "run" an outside program using a Process, similar to the code above, but using a String that is similar to a String that would allow you to run the program from the command line in your current OS/platform. Current recommendation is to use a ProcessBuilder for this. You can learn how to use this from the ProcessBuilder API which I've linked to. You're going to have to experiment some and then let us know what happens.
    So how can I do that for running Windows Live Messenger, please give me an example... with the code above but edit some that i can run MSN messenger.. (-:

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: java help.. pasting from you java written program into another window?

    As Fubarable says:
    "You're going to have to experiment some and then let us know what happens."
    DarrylBurke and Fubarable like this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    delete123 is offline Member
    Join Date
    Jul 2012
    Posts
    4
    Rep Power
    0

    Default Re: java help.. pasting from you java written program into another window?

    Quote Originally Posted by Tolls View Post
    As Fubarable says:
    "You're going to have to experiment some and then let us know what happens."
    but i tried alot and it seems to be not working at all, i just requires to change up to 2 lines, why are you avoiding it.... please (:

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: java help.. pasting from you java written program into another window?

    Quote Originally Posted by delete123 View Post
    but i tried alot and it seems to be not working at all, i just requires to change up to 2 lines, why are you avoiding it.... please (:
    We're not the ones avoiding this issue; you are. This is your problem and the onus of effort should be yours. So let's see what you've tried and what has happened with your efforts.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: java help.. pasting from you java written program into another window?

    Quote Originally Posted by delete123 View Post
    but i tried alot and it seems to be not working at all, i just requires to change up to 2 lines, why are you avoiding it.... please (:
    I've never done this, which is why I'm avoiding it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Cannot run Java program in command window
    By tricky in forum New To Java
    Replies: 4
    Last Post: 03-19-2012, 06:03 AM
  2. Written Java Program in Netbeans won't compile..
    By ptrasd12 in forum New To Java
    Replies: 5
    Last Post: 12-01-2011, 01:43 PM
  3. Backup Tool Entirely Written in JAVA
    By rajyarr in forum Advanced Java
    Replies: 5
    Last Post: 04-06-2011, 04:37 AM
  4. I need some java / html code written
    By DeDanan in forum New To Java
    Replies: 2
    Last Post: 03-01-2011, 09:36 AM
  5. Replies: 24
    Last Post: 12-03-2009, 10:58 PM

Posting Permissions

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