Getting one java program to compile another

Was wondering if anyone knew if it is possible ot get one java program to compile another .java file and capture any errors.

public static void RunCommand( String theCommand ) throws Exception
Runtime runtime = Runtime.getRuntime();
System.out.println( "Running Command " + theCommand ) ;
Process process = runtime.exec(theCommand);
String s = null ;
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
     System.out.println(s);
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
     System.out.println(s);

Similar Messages

  • Not able to execute one Java program from another one via. exec()

    Hi,
    I am new to this forum, so I might be asking a very trivial quetion.
    My program Ap1 is :
    class Ap1
    public static void main(String a[]) throws Exception
    Runtime rt=Runtime.getRuntime();
    Process p=null;
    p=rt.exec("javac,Pr.java");
    Runtime.getRuntime().exec("javac,Pr.java");
    When I run the above program, I get below error at the line 7(bold one):
    D:\batchwe>javac Ap1.java
    D:\batchwe>java Ap1
    Exception in thread "main" java.io.IOException: CreateProcess: javac,Pr.java err
    or=2
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
    at java.lang.ProcessImpl.start(ProcessImpl.java:30)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
    at java.lang.Runtime.exec(Runtime.java:591)
    at java.lang.Runtime.exec(Runtime.java:429)
    at java.lang.Runtime.exec(Runtime.java:326)
    at Ap1.main(Ap1.java:7)
    Path is set as below(which seems correct):
    D:\batchwe>path
    PATH=C:\Program Files\Java\jdk1.5.0_05\bin
    I am just wondering how to call one Java program from another one?!
    Please help.
    thanks
    Rashmi

    Hi diptaPB,
    Thanks for your suggestion.
    Here is how I tried it again, but not getting the desired output:
    Class Pr looks like below -->
    class Pr
    public static void main(String a[])
    System.out.println("hi from process");
    When I run 'Pr' from command prompt, i get the desired output:
    D:\batchwe>java Pr
    hi from process
    However, when I call 'Pr' from another program Ap2.java, it seems that it does not call 'Pr':
    class Ap2
    public static void main(String a[]) throws Exception
    Runtime rt=Runtime.getRuntime();
    Process p=null;
    String[] cmd=new String[2];
    cmd[0]="javac";
    cmd[1]="Pr.java";
    p=rt.exec("cmd");
    D:\batchwe>javac Ap2.java
    D:\batchwe>java Ap2
    ************* no output appears here***********************
    Looking forward for your help.
    regards
    Rashmi

  • I am trying to get this java program to work

    I need your help, I am trying to get this java program to work. The program is long and massive, but I got stuck in the last point where the program checks if there are a double quotes or a comma in a string.
    The string is an URL retrieved from XML files (this is already done).
    There are 4 conditions:
    Case 1
    =====
    The URL string is of invalid format and contains no commas (,) and no double quotes (").
    Make no changes to the URL string.
    Case 2
    =====
    The URL string is of invalid format and contains 1 or more double quotes (") but no commas.
    Make no changes to the URL string.
    Case 3
    =====
    The URL string is of invalid format and contains 1 or more commas (,) but no double quotes.
    Modify the URL string so that it starts and ends with a double quote (").
    Case 4
    =====
    The URL string is of invalid format and contains 1 or more double quotes (") and one or more commas (,).
    Modify the URL string so that every double quote (") becomes a double double quote (""), and so that it starts and ends with a double quote (").
    ======
    then write the modified URL string to the CSV file.
    ======
    Examples:
    1. hello ---> hello
    2. hello "big" world ---> hello "big" world
    3. hello, world ---> "hello, world"
    4. hello "big,big" world ---> "hello ""big,big"" world"

    You can do the searching with String.indexOf() and then you can make replacements (like " with "") with String.replaceAll().
    As for adding leading and trailing ", that could be done with simple concatenation.

  • Help--How can I open only one java program at one time?

    How can I open only one java program(same program) in Windows at one time?

    In Java 1.5, you can use the JVM's own monitoring APIs to examine what other JVMs are running on the system, and what applications they're running.
    It's general and powerful, but complex. The socket/file/whatever approach is cleaner, and probably more suited to your usage.
    Don't bother trying to use the Windows task manager for this sort of thing. You have to write messy native code, and it isn't reliable after all that anyway.

  • Compiling one java program by another

    hi ppl
    how to compile a java program by another java program by using javac command.
    that is prog A must compile prog B using " javac B.java" command

    Try com.sun.tools.javac.Main.
    You require JDK_HOME/lib/tools.jar in CLASSPATH.

  • Calling one java program (with main method) from another

    Hello,
    How can I start another java program from one? Lets
    say I want Second.java to start by calling it from
    First.java. How do I do it? The two programs are given
    below. Any help is appreciated.
    Thanks,
    Amanda
    First.java
    import java.io.*;
    import java.lang.reflect.*;
    public class  First
         public static void main(String[] args)
              Process theProcess=null;
              System.out.println("Hello World from First.java!");
              String second=new String("Second.java");
              //System.load(second);
              //Runtime.getRuntime().load(second);
              try
                   theProcess=Runtime.getRuntime().exec( "Second.java"
                   System.out.println("after exec");
              catch (IOException ioe)
                   System.out.println(">>IOException thrown in
    First.java while calling
    Second.java."+ioe.getMessage());
    Second.java
    public class  Second
         public static void main(String[] args)
              System.out.println("Hello World from Second.java!");
    }

    Stop posting here. The crosspost remark was to alert others that there is a duplicate topic - all answers should be centralized in one so as to not waste people's time duplicating answers when they don't see both topics and the answers therein.

  • Calling one java program from another

    Hello,
    How can I start another java program from one? Lets
    say I want Second.java to start by calling it from
    First.java. How do I do it? The two programs are given
    below. Any help is appreciated.
    Thanks,
    Amanda
    First.java
    import java.io.*;
    import java.lang.reflect.*;
    public class  First
         public static void main(String[] args)
              Process theProcess=null;
              System.out.println("Hello World from First.java!");
              String second=new String("Second.java");
              //System.load(second);
              //Runtime.getRuntime().load(second);
              try
                   theProcess=Runtime.getRuntime().exec( "Second.java"
                   System.out.println("after exec");
              catch (IOException ioe)
                   System.out.println(">>IOException thrown in
    First.java while calling
    Second.java."+ioe.getMessage());
    Second.java
    public class  Second
         public static void main(String[] args)
              System.out.println("Hello World from Second.java!");
    }

    Thanks, warnerja
    What if Second.java is on a remote machine i.e.
    First.java and second.java are on different machines?
    Will I have to use RMI?Well, you'd have to do some kind of remote invocation. Depends on what kinds of apps house the classes. There are all kinds of ways - web services, servlets, RMI, (maybe others...)
    That's a totally different question than what you originally posted, and would have been very relevant to say so in the first place.

  • How can you get a java program working on a cell phone?

    I was thinking of making some stuff for cell phones so i was wondering how you get a normal java program to work on cells.

    its all j2me - midlet package....Huh? The jsr-118 MID profile alone has 11 packages, one of which is javax.microedition.midlet. Notj2me - midlet.
    works best on nokia phones.Sez who? You seem to be confusing Java ME with Symbian C.
    you can use net beans midlet packge add-on.Only it's called the NetBeans Mobiliity Pack.
    Its easy to use and has lots of tutorials.Ditto for the Wireless toolkit for CLDC.
    just search on google.Yes, but with which keywords?
    @OP:
    NetBeans mobility pack comes with a short tutorial and several samples, you also need to download the latest WTK as the ver. 2.2 which comes bundled with NetBeans is just too buggy to work with. Then there are the manufacturer-specific SDKs from Nokia, Motorola, Sony Ericsson and (maybe) others.
    If and when you get started in Java ME aka j2me, it will be appropriate to post any questions you might have on the mobility forums, not here.
    Google "j2me tutorial" for many good hits.
    luck, db

  • How To Get A Java Program To Initiate Auto Dial in Windows???

    I have a Java program that opens a connection to a server (another Java program) using sockets and streams. On some windows machines (various versions) with auto dial enabled the connection is made without human intervention. However on some windows machines (even same as others) the autodial doesn't work and all I receive is NoRouteToHostExceptions.
    What I need is some way of initiating the autodial from within Java explicilty rather than assuming that the OS will do it when a request is made to a remote IP address.
    I emplore anyone with some knowledge of this to provide assistance as I am going nuts trying to solve this problems.

    A long time ago I figured out how to create, find, and manipulate items in the DialUp Networking using an InstallShield program. I am sorry I can't remember specifics (I wouldn't have even replied except no one else has either...) but I remember that I did a LOT of hunting on Microsoft's website for how to do this on the various platforms of the day (Win95, Win98, NT4.0).
    I imagine that in order to accomplish this from java, you will probably need to find the system-specific commands (at Microsoft) and exec them from your java program.
    /Mel

  • Method to get working Java program on a PDA

    Hello all,
    I am attempting to create a java program for my PDA. I'm trying to use CrEme to do it but I am having many many problems with it. I've looked on the forums and they all appear to be posts where people have some clue. I have none.
    For example. Can you use any sdk to develop the program. Can you simply develop a desktop app and convert it to use on a PDA?
    Once CrEme is downloaded what do you have to add to the classpath on your desktop to compile with it. Up till now I've simply compiled with the standard java system using %javac my_app.java
    What do you type in the command line to run the emulator?
    In what form should you port the program to your pda? I've tried using .jar files. I load it and nothing happens. What do I have to type in the jRun command? Whats a .lk file and how do I use it?
    So many questions so little time. I am genuinly confused by all this and some help would be appreciated. I have looked around the internet and can find little or nothing to help a pda newbie . Incidently if I have missed anything online and this is all just wasting someones time, could they show me where I've missed it?
    Thanks a lot
    N

    I built a lot of applications to run on my PDA (Sharp Zaurus SL5500). When I first got the PDA I didn't know any Java. What I do, and it may not be useful to you, is to develop on my desktop using as few classes not supported in 1.0 as I can get away with. That seems to make the code runnable on the Zaurus JVM (which is JEODE). I don't use an interactive development environment (I never have gotten the hang of them); I just use a text editor that supports syntax highlighting (CONTEXT). Then I copy the compiled classes to the PDA and run them there.

  • Execute a java program from an another program

    Like we can compile a code from wihin a java file by using the following :
    Tool javac = ToolProvider.getSystemJavaCompiler();
    Similarly,can we execute i.e. run a java program from within a java file i.e. running d java command from within the java file ??If yes then please tell me how??

    suppose on the Unix box or from a Unix script ( korn, perl, bourne, bash) you can run the following java program
    java ${JAVA_OPTS} -jar ${GMR_APPS_DIR}/risk.jar -I -c ${COB} -r ${BATCH} -o ${XML_DIR}
    in java you can do the following :
    Runtime rt = Runtime.getRuntime();
              try {
                   Process process = rt.exec("java ${JAVA_OPTS} -jar ${GMR_APPS_DIR}/risk.jar -I -c ${COB} -r ${BATCH} -o ${XML_DIR}
    // OR
                   Process process = rt.exec("/export/apps/Tools/apache-tomcat-5.5.17/bin/startup.sh");
                   // process.destroy(); if you want to kill the process
                   process.waitFor();
                   int RC = process.exitValue();      
                   System.out.println(returnOutput(process.getErrorStream()));
                   System.out.println(returnOutput(process.getInputStream()));
              } catch (Exception ex) {
                   ex.printStackTrace();
    empty the output stream from the script
    private String returnOutput(InputStream is) throws Exception {
                   String s;
                   StringBuffer strBuff = new StringBuffer();
                   BufferedReader br = new BufferedReader(new InputStreamReader(is));
                   while ((s = br.readLine()) != null) {
                        strBuff.append(s);
                   return strBuff.toString();
              }You need to relace the ${} by the appropriate values.
    Regards,
    Alan Mehio
    London, UK
    Edited by: alan_mehio on Jan 16, 2008 4:21 PM

  • How a java program accessable by another java program?

    Dear all,
    Iam had developed a program which talks to serial port. This program should be intergrated with another main java program . I don't want a function (subroutine )call to my program. i want any other methods to access my program by main java program , which should be fast.

    You could serach for "interprocess communication". The main techniques available are pipes and share memory. This means that the two Java programs run as totally separated processes.
    An easier way is to restructure the "serial port talking" program into a "utility package with an API" and integrate it with the "main" program. You could let the "serial port talker" run in it's own thread thus creating an illusion of total independency from "main".

  • Passing variable from one java source file to another

    i have one java source file
    one.java
    class one {
    long a;
    a = somevalue;
    i have another java source file
    second.java
    class second{
    long b;
    // here i need to assign the value of a i.e from one.java to b
    i am in great confusion and begineer of java
    plz plz help me

    a couple of possibilities are
    pass a parameter to the constructor
    or
    use the reference to class Two to call a method in class Two that takes a parameter and sets the value of the attribute in class Two.

  • Calling FND_VAULT.get from Java program

    Hi,
    I am creating a Java Concurrent Program in EBS and from my Java program I want to invoke "FND_VAULT.get" procedure.
    Can someone please guide me on how to do that.
    Thanks

    Actually I am having 4 Shell Scripts which I want to
    call at a time.
    1)run_graph.sh
    2)run_report.sh
    3)web_report.sh
    4)mktg_report.sh
    Now I want to call all the four from a Java Program at
    the same timeWell... if you truly want to run them at the same time, you'll need to look into multithreading.
    What I suspect you really want is to run them in the above order within the same Java program.
    String pathToScripts = "/etc/path/to/your/scripts/";
    String[] scripts = {"run_graph.sh", "run_report.sh", "web_report.sh", "mktg_report.sh"};
    Process p = null;
    for (int i=0; i<scripts.length; i++){
        p = Runtime.getRuntime().exec(pathToScripts + scripts);
    p.waitFor();
    System.out.println(scripts[i] + " completed with exit code " + p.exitValue());
    If you want to capture output or send input for the above processes, see the java.lang.Process and java.lang.Runtime API docs:
    http://java.sun.com/j2se/1.3/docs/api/java/lang/Runtime.html
    http://java.sun.com/j2se/1.3/docs/api/java/lang/Process.html
    Hope this helps,
    -Scott

  • Trouble getting a JMF program working with another program

    hello.
    my name is james mcfadden. i am having difficulty compiling the first program (a menu GUI) here. even though the second program (the JMF program) can be compiled and runned as a separate application, i'm trying to get be able to use the first program to run the second program. when i compile the first program i get the following errors. i don't know what are causing these errors?
    ----jGRASP exec: javac -g X:\CP4B Project\Demo.java
    Demo.java:284: cannot find symbol
    symbol : constructor Media()
    location: class Media
    Media media=new Media();
    ^
    Demo.java:288: cannot find symbol
    symbol : constructor Media()
    location: class Media
    Media media=new Media();
    ^
    Demo.java:292: cannot find symbol
    symbol : constructor Media()
    location: class Media
    Media media=new Media();
    ^
    3 errors
    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.
    //Written by:Seamus McFadden
    //Class:CP4B
    //Program Number:1
    //Program Name:Demo.java
    //Description:
    //Supervisor:Gerard McCloskey
    import java.awt.*;//Contains all of the classes for creating user interfaces and for painting graphics and images
    import java.awt.event.*;//Provides interfaces and classes for dealing with different types of events fired by AWT components
    import javax.swing.*;//Provides a set of lightweight components that, to the maximum degree possible, work the same on all platforms
    public class Demo extends JFrame{
        public static void main(String[] args){
            int choice=-1;//a variable of type int that is set to -1
            do{
               choice=getChoice();//invokes the method getChoice()
               if(choice!=0){
                   getSelected(choice);//invokes the method getSelected(choice)
               }//end if
               //if the user chooses 4, it will cause him or her to exit the system
            }while(choice!=5);//end do-while
            System.exit(0);//closes down the menu screen
        }//end main
        public static int getChoice(){
            String choice;//a variable of type string
            int ch;//a variable of type int
            choice=JOptionPane.showInputDialog(null,
                    "1. Product Menu\n" +
                    "2. Member Menu\n" +
                    "3. Rental Menu\n" +
                          "4. Media Menu\n" +
                    "5. Log Off\n\n" +
                    "Enter your choice");//asks the user for some input
            ch=Integer.parseInt(choice);//a class that wraps a value of the primitive type int in an object
            return ch;//a method that returns an integer value
        }//end getChoice
        public static void getSelected(int choice){
            if(choice == 1) {
                   product();
            }//end if
            if(choice==2){
               member();
            }//end if
            if(choice==3){
               rental();
            }//end if
                if(choice==4){
               media();
            }//end if
        }//end getSelected
        public static void product(){
             int productChoice=-1;//a variable of type int that is set to -1
           productChoice=getProductChoice();//invokes the method getChoice()
           if(productChoice!=0){
              getProductSelected(productChoice);//invokes the method getSelected(choice)
           }//end if
           System.exit(0);//closes down the menu screen
        public static void member(){
           int memberChoice=-1;//a variable of type int that is set to -1
           memberChoice=getMemberChoice();//invokes the method getChoice()
           if(memberChoice!=0){
              getMemberSelected(memberChoice);//invokes the method getSelected(choice)
           }//end if
           System.exit(0);//closes down the menu screen
        public static void rental(){
           int rentalChoice=-1;//a variable of type int that is set to -1
           rentalChoice=getRentalChoice();//invokes the method getChoice()
           if(rentalChoice!=0){
              getRentalSelected(rentalChoice);//invokes the method getSelected(choice)
           }//end if
           System.exit(0);//closes down the menu screen
          public static void media(){
           int mediaChoice=-1;//a variable of type int that is set to -1
           mediaChoice=getMediaChoice();//invokes the method getChoice()
           if(mediaChoice!=0){
              getMediaSelected(mediaChoice);//invokes the method getSelected(choice)
           }//end if
           System.exit(0);//closes down the menu screen
          public static int getProductChoice(){
           String productChoice;//a variable of type string
           int pch;//a variable of type int
           productChoice=JOptionPane.showInputDialog(null,
                   "1. Add product details\n" +
                   "2. View product details\n" +
                   "3. Edit product details\n" +
                         "4. Delete product details\n" +
                   "5. Exit\n\n" +
                   "Enter your choice");//asks the user for some input
           pch=Integer.parseInt(productChoice);//a class that wraps a value of the primitive type int in an object
           return pch;//a method that returns an integer value
        }//end getChoice
          public static int getMemberChoice(){
           String memberChoice;//a variable of type string
           int mch;//a variable of type int
           memberChoice=JOptionPane.showInputDialog(null,
                   "1. Add member details\n" +
                   "2. View member details\n" +
                   "3. Edit member details\n" +
                             "4. Delete member details\n" +
                   "5. Exit\n\n" +
                   "Enter your choice");//asks the user for some input
           mch=Integer.parseInt(memberChoice);//a class that wraps a value of the primitive type int in an object
           return mch;//a method that returns an integer value
        }//end getChoice
          public static int getRentalChoice(){
           String rentalChoice;//a variable of type string
           int rch;//a variable of type int
           rentalChoice=JOptionPane.showInputDialog(null,
                   "1. Add rental details\n" +
                   "2. View rental details\n" +
                   "3. Edit rental details\n" +
                             "4. Delete rental details\n" +
                   "5. Exit\n\n" +
                   "Enter your choice");//asks the user for some input
           rch=Integer.parseInt(rentalChoice);//a class that wraps a value of the primitive type int in an object
           return rch;//a method that returns an integer value
        }//end getChoice
          public static int getMediaChoice(){
           String mediaChoice;//a variable of type string
           int mtch;//a variable of type int
           mediaChoice=JOptionPane.showInputDialog(null,
                   "1. Listen to songs\n" +
                             "2. View movie previews\n" +
                             "3. View game previews\n" +
                   "4. Exit\n\n" +
                   "Enter your choice");//asks the user for some input
           mtch=Integer.parseInt(mediaChoice);//a class that wraps a value of the primitive type int in an object
           return mtch;//a method that returns an integer value
        }//end getChoice
          public static void getProductSelected(int productChoice){
           if(productChoice==1){
                  addProducts();
           }//end if
           if(productChoice==2){
              viewProducts();
           }//end if
           if(productChoice==3){
              editProducts();
           }//end if
               if(productChoice==4){
              deleteProducts();
           }//end if
        }//end getSelected
          public static void getMemberSelected(int memberChoice){
           if(memberChoice==1){
                  addMembers();
           }//end if
           if(memberChoice==2){
              viewMembers();
           }//end if
           if(memberChoice==3){
              editMembers();
           }//end if
               if(memberChoice==4){
              deleteMembers();
           }//end if
        }//end getSelected
          public static void getRentalSelected(int rentalChoice){
           if(rentalChoice==1){
                  addRentals();
           }//end if
           if(rentalChoice==2){
              viewRentals();
           }//end if
           if(rentalChoice==3){
              editRentals();
           }//end if
               if(rentalChoice==4){
              deleteRentals();
           }//end if
        }//end getSelected
          public static void getMediaSelected(int mediaChoice){
           if(mediaChoice==1){
                  hearSongs();
           }//end if
           if(mediaChoice==2){
              viewMovies();
           }//end if
           if(mediaChoice==3){
              viewGames();
           }//end if
        }//end getSelected
          public static void addProducts(){
           ProductForm product=new ProductForm();
           product.getInput();
               product.setVisible(true);
          public static void viewProducts(){
           DatabaseTest tt=new DatabaseTest();
               tt.setVisible(true);
          public static void editProducts(){
           ProductForm product=new ProductForm();
               product.getInput();
               product.setVisible(true);
          public static void deleteProducts(){
           ProductForm product=new ProductForm();
               product.setVisible(true);
          public static void addMembers(){
           MemberForm member=new MemberForm();
               member.getInput();
               member.setVisible(true);
          public static void viewMembers(){
           DatabaseTest tt=new DatabaseTest();
               tt.setVisible(true);
          public static void editMembers(){
           MemberForm member=new MemberForm();
               member.getInput();
               member.setVisible(true);
          public static void deleteMembers(){
           MemberForm member=new MemberForm();
               member.setVisible(true);
          public static void addRentals(){
           RentalForm rental=new RentalForm();
               rental.getInput();
               rental.setVisible(true);
          public static void viewRentals(){
           DatabaseTest tt=new DatabaseTest();
               tt.setVisible(true);
          public static void editRentals(){
           RentalForm rental=new RentalForm();
               rental.getInput();
               rental.setVisible(true);
          public static void deleteRentals(){
           RentalForm rental=new RentalForm();
               rental.setVisible(true);
        public static void hearSongs(){
           Media media=new Media();  
        public static void viewMovies(){
           Media media=new Media();   
        public static void viewGames(){
           Media media=new Media();   
    }//end class Demo
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.io.IOException;
    import java.net.URL;
    import javax.media.CannotRealizeException;
    import javax.media.Manager;
    import javax.media.NoPlayerException;
    import javax.media.Player;
    import javax.swing.JPanel;
    import java.io.File;
    import java.net.MalformedURLException;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    public class Media extends JPanel{
       public Media(URL mediaURL){
          setLayout(new BorderLayout());//use a BorderLayout
          //Use lightweight components for Swing compatibility
          Manager.setHint(Manager.LIGHTWEIGHT_RENDERER,true);
          try{
             //create a player to play the media specified in the URL
             Player mediaPlayer=Manager.createRealizedPlayer(mediaURL);
             //get the components for the video and the playback controls
             Component video=mediaPlayer.getVisualComponent();
             Component controls=mediaPlayer.getControlPanelComponent();
             if(video!=null)
                add(video,BorderLayout.CENTER);//add video component
             if(controls!=null)
                add(controls,BorderLayout.SOUTH);//add controls
             mediaPlayer.start();//start playing the media clip
          }//end try
          catch(NoPlayerException noPlayerException){
             System.err.println("No media player found");
          }//end catch
          catch(CannotRealizeException cannotRealizeException){
             System.err.println("Could not realize media player");
          }//end catch
          catch(IOException iOException){
             System.err.println("Error reading from the source");
          }//end catch
       }//end Media constructor
       // launch the application
       public static void main( String args[] ) {
          // create a file chooser
          JFileChooser fileChooser = new JFileChooser();
          // show open file dialog
          int result = fileChooser.showOpenDialog( null );
          if ( result == JFileChooser.APPROVE_OPTION ) {
             URL mediaURL = null;
             try {
                // get the file as URL
                mediaURL = fileChooser.getSelectedFile().toURL();
             } // end try
             catch ( MalformedURLException malformedURLException ) {
                System.err.println( "Could not create URL for the file" );
             } // end catch
             if ( mediaURL != null ) {
                JFrame mediaTest = new JFrame( "Media Tester" );
                mediaTest.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
                Media mediaPanel = new Media( mediaURL );
                mediaTest.add( mediaPanel );
                mediaTest.setSize( 300, 300 );
                mediaTest.setVisible( true );
             } // end inner if
          } // end outer if
       } // end main
    }

    hello.
    thanks for the reply. how do i create argument
    constructors in Java?Please re-read my post ... you already have one. If you want to use it, simply pass in the argument to it that it wants. In this case it wants a URL (Universal Resource Locator). Please check out the java.net.URL package in the [url http://java.sun.com/javase/6/docs/api/]API doco.
    You can build a URL like this:
    URL url = getClass().getResource( "textfile.txt" ); // Just an example - where the file resides in the same location as the class file.

Maybe you are looking for