I use netbeans to run a code and in this code I have to put arguments
I did it in this way Run-->Debug Configurations-->Java Application and select arguments and there I put the path of the files which I used for arguments.
Now I want to build an application and to give arguments not in this way but by writing code (write the path in a JTextField and then use it as an argument).
You can put anything you like in a text field, as long as it's text. You can pass it as an argument to another method. If, however, you wish to find a path, you might do better to try a file chooser.
Joined: May 20, 2011
Campbell Ritchie wrote:You can put anything you like in a text field, as long as it's text. You can pass it as an argument to another method. If, however, you wish to find a path, you might do better to try a file chooser.
how can I do this?
because eclipse take the arguments in the way I wrote before
When you talk about Netbeans and Eclipse it makes me think you are talking about passing arguments to the
method of your class, the one which is called to start it running.
Am I right?
And it seems as if now you want to do something else instead of that, for example using a file chooser to pick a file to be used by the code.
Is that right?
If so, then don't waste your time trying to hack things so that you somehow run some code which passes arguments to the static main method. Just stop using the parameters there and write code which does what you want.
Are you going to be calling this from the same project? If so, it's easy.
e.g. if your main method is in class com.mypackage.ABC,
If you want to kick off the project from another project, you'll have to set up your classpath for the launcher code so that it can find the class directories of your other projects.
Joined: May 20, 2011
this is a part of the code in which I need the arguments
yes from the same project
so I write your code? and I am ok?
am I right about the arguments?
No this is wrong: the split method just takes an argument which is the separator that you want to use to split the String, which comes from the getText() method. Look it up.
As Mr Clapham mentions, it's not generally a great idea to have code invoking a main method. In well-designed code, the main method should be very short and just used as an entrypoint to kick things off. If you're coming from another method, you have already kicked things off and it should be just as easy to replicate the instructions in the main method from whereever you are.