Jump to content


Using Args In Jcreator


  • Please log in to reply
8 replies to this topic

#1 WaNaBeWiThYoU

WaNaBeWiThYoU

    Member

  • Members
  • PipPip
  • 10 posts

Posted 29 April 2005 - 09:32 PM

Hi every one .. this is my first topic in fourms ...

My Question is how can I give an arguments for a code before it been executed ..

public static void main( String args[]) .. I mean here o give main args to use it in program like args[0] , args[1] ...  etc

This could be executed in old Java when execute program , ex for class xyz:

c:\java\bin>java xyz "Hi" "localhost"

Thanks for your time

#2 Sahisoft

Sahisoft

    Advanced Member

  • Members
  • PipPipPip
  • 74 posts
  • Gender:Male
  • Location:New Jersey, United States
  • Interests:Computer science. What else? :-)

Posted 30 April 2005 - 04:04 AM

Here is how to do it:

1) Go to Configure >> Options.
2) In the option dialog, go to JDK Tools in the left panel.
3) For tool type, choose "Run Application" from the drop-down list, and then select <Default>.
4) Click Edit.
5) Go to the Parameters tab and select the check box "Prompt for main method arguments."

And now when you run your program, it will ask for parameters.

#3 WaNaBeWiThYoU

WaNaBeWiThYoU

    Member

  • Members
  • PipPip
  • 10 posts

Posted 30 April 2005 - 04:02 PM

Will i want to make my question more specified ..

is this operation can happen only for one class .. without see the dialog of args in any other class tongue.gif

#4 Sahisoft

Sahisoft

    Advanced Member

  • Members
  • PipPipPip
  • 74 posts
  • Gender:Male
  • Location:New Jersey, United States
  • Interests:Computer science. What else? :-)

Posted 01 May 2005 - 02:30 AM

It is for the main method only. What you specify here is the values in args[]. The rest of the program runs normally, no additional input is required.

#5 ruggles

ruggles

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 05 May 2005 - 10:46 AM

I have done this (it was clearly described in the help system too), but it has not worked.

I have re-compiled and then run the program, and it does not prompt for any arguments.  I am using the LE (free) version, if this makes any difference.

I am running through an introductory course, and the prog I am currently writing is called NewRoot (a standard calculate the square root beginner app).  I have tried setting the 'Run Application, Prompt for main method arguments' check box with a Name of NewRoot, and also NewRoot.class  - neither worked for me.

Any ideas where I may be going wrong ?

Win XP and JCreator 3.50 LE (version 3.50.012)

The prog is :

class NewRoot {
public static void main (String[] arguments) {
int number = 0;
if (arguments.length > 0)
         number = Integer.parseInt( arguments[0] );
System.out.println("The square root of " + number
+ " is " + Math.sqrt(number));
}
}

There is not something I'm missing here is there ?

Matt

#6 WaNaBeWiThYoU

WaNaBeWiThYoU

    Member

  • Members
  • PipPip
  • 10 posts

Posted 07 May 2005 - 05:03 PM

CODE

class NewRoot {
public static void main (String[] arguments) {
int number = 0;
if (arguments.length > 0)
number = Integer.parseInt( arguments[0] );
System.out.println("The square root of " + number
+ " is " + Math.sqrt(number));
}
}


the code is working with no problems but u seem that u don't send args b4 begining the execution of the program . does u ?

#7 ruggles

ruggles

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 11 May 2005 - 10:47 AM

Thanks for replying, but I couldn't understand the answer.

I believe that I should be able to bring up a prompt for arguments to pass to the program by setting the 'prompt for main method arguments' flag, but I am not getting any prompt.  Are you saying that the code needs to be changed to look for an argument ?  As I mentioned, I am working through course examples, and according to the course this should work.  If this were in RPG I would have no problems, but this modern stuff is still a little bit of a mystery to me - hence the call for help.

Do I need to change the code, or should this work ?

Thanks for any help you can provide.

#8 E-E-R

E-E-R

    Advanced Member

  • Members
  • PipPipPip
  • 1,367 posts
  • Gender:Male
  • Location:The Netherlands
  • Interests:Programming, Gaming, DC

Posted 11 May 2005 - 12:10 PM

I made a screenshot of the option you should set, I set it and it works here.

user posted image

"Many are persistently in pursuit of the way they have chosen; few in pursuit of the goal"

#9 ruggles

ruggles

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 11 May 2005 - 01:35 PM

Thanks for your help.  I think I have found what I was doing wrong.  I had not set up a project, and was working with 'external files'.  I copied the source into a project.  Initially it still would not work as expected, but did so once I had set the checkbox under the Toolbar's 'Execute' drop-down menu's configure section !  (Whew ... sorry about that sentence  blush.gif )