File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes arguments by using code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "arguments by using code" Watch "arguments by using code" New topic
Author

arguments by using code

Dim Dioannou
Greenhorn

Joined: May 20, 2011
Posts: 6
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).

Is it possible?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39053
    
  23
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.
Dim Dioannou
Greenhorn

Joined: May 20, 2011
Posts: 6
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
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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.
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

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.
Dim Dioannou
Greenhorn

Joined: May 20, 2011
Posts: 6
@Paul Clapham
not exactly

this is a part of the code in which I need the arguments



@Luigi Plinge
yes from the same project

so I write your code? and I am ok?
am I right about the arguments?

Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

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.
 
GeeCON Prague 2014
 
subject: arguments by using code