• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

arguments by using code

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Marshal
Posts: 78653
374
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Marshal
Posts: 27987
94
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 441
Scala IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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
Posts: 441
Scala IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
It's a tiny ad. At least, that's what she said.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic