Hi all
I m working on this project where i need to get user input and then see if the user input is correct or not. if it is correct then show the user input in the label but if the user input is wrong then show user a warning message. now i got the text field, button and label working for right now whenever user input any thing in the text field it just shows the user input in the label. so now i want to add that extra feature to my program which is when ever user input anything my program needs to compare the user input to the file which I got. now i have to compare user input and compare with the file i got and then show the error message if it is wrong. so i m having problem to link to that file and how can i compare user input through that file and based on that file give user a right message. Any help please.
I m working on this project where i need to get user input and then see if the user input is correct or not.
-> Ok so you need to determine if the user input is correct or not.
if it is correct then show the user input in the label but if the user input is wrong then show user a warning message.
-> A Modal Dialog Box immediately comes to mind for the warning. The Label is obvious – if the answer is correct then either generate a label with the answer or setText of an existing label to the answer when it is correct.
now i got the text field, button and label working for right now whenever user input any thing in the text field it just shows the user input in the label.
-> Ok so the label takes any input from the user and shows it in the label (whether it is right or wrong).
so now i want to add that extra feature to my program which is when ever user input anything my program needs to compare the user input to the file which I got.
-> Ok now we’re talking about files? You’ll most likely need to retrieve information from the file and convert it into Text, or if your file is an object file you’ll need to deserialize the object file into the proper object type(s) and store the information in your program either at the beginning or some time before the user processes input – it would be a real hassle for this process to be done DURING input.
now i have to compare user input and compare with the file i got and then show the error message if it is wrong.
-> Once again, once you retrieve the data from the file and store it in proper data types (String comes to mind) you can compare the String input of the user and invoke the compareTo method (or the equalsIgnoreCase method) to compare the string data of the user input to the string data retrieved from the file that was stored in some string data type.
so i m having problem to link to that file and how can i compare user input through that file and based on that file give user a right message. Any help please.
-> One step at a time. Open the file and read the contents of the file as a Text file and store the data into a String, or store each line into an empty ArrayList<String> . Afterwards compare the input of the user to the stored data. Obviously you’ll have to keep track of which line (or value) refers to which question after retrieving the information. Then either use the method in String called compareTo or use equalsIgnoreCase OR if needed you can make a map with a set of keys that are “answers” and compare the retrieved value from the map to the answer (since the value returned by the key can be null don’t use compareTo in that case to prevent a null pointer error – instead use a condition that warns the user that he/she is wrong when this even occurs).
You’ll have to show some work if you want a valid example, through your version of course.
Thank you for your help, i understood some of the things but still not clear.
ok what i want is to user input its value in the text field ok then that file will only see if the user enter right value or not. for example, user must start with digit so first value have to be digit and then it can use some character then after five word user have to input digit again so i want that the user input needs to compare with that file to see the format so this file will compare user input and compare that the format is correct or not if it is correct the show that text on the label but if the input is wrong then show the error message. In other words in this file the specs and format is already created so all i have to make my program to compare user input with that file to see if the user input is correct or wrong. so far i don't have that file link with my program so whenever enter something its not checking if it is correct or wrong it just show that value in the
How about posting your code? That would be slightly more helpful.
Edit: If you're trying to determine if a File exists or not you should use the File class. I do believe there is a method that returns true if a file exists within the given directory or returns false if it doesn't.
If not, it isn't hard to iterate through Files in a given directory using the File class.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.