just a logical question
ive never done anything like this before, so maybe someone can help me out with some logic instead of code. ok, so if a user inputs(in my program) lets say a specific command with parameters. for example: fruit(apple,orange,berry); how can i check that there are parameters specified. so if a user enters fruit(); with no parameters, return an error. and if parameters are present, split them up. can someone help me out?
Last edited by Waylander; 12-11-2005 at 11:08 PM.
Im not sure exactly what you mean, if your talking about directly inputing the command as text read it as a string and parse the text... I would replace each bracket comma and semi-colon with a space character, and then use the array split method to split the string into an array. The first index would be the function name and the rest would be the parameters, it would work well too because double or more occurances of the split character dont match... there has to be something else between them so once all the syntax is out of the way you would only get the important stuff.
If you mean in code sense like if you were setting the text for the contents of the parameters from inside text fields or something then it would be better and easier to validate the gui itself rather than to check for it later within the code.
Last edited by Waylander; 12-11-2005 at 11:15 PM.
i understand what your saying. i will try it out tomorow. thanks again.
If you want to call a method based on user input as in something from a text box which is put into your application at run time after the classes are compiled you will need to use reflection to look for the class and method names, the stuff can get fairly tricky..
The class is java.lang.reflect, I would suggest reading the api.
Last edited by Waylander; 12-12-2005 at 03:07 PM.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)