Hi guys. First post. I have to write a program that allows the user to input his or her name. If the user type all lowercases the program should be able to convert to first letter of the name to uppercase. Also, if the user press "enter" without entering the name then the program has to display a message saying that the field is required. My problem is : i have the uppercase part right, but if i press enter without entering the name then i get a lot of errors. What do you suggest?
Thanks for your help.
here is the code corresponding to that part:
public void actionPerformed(ActionEvent e) {
firstNameAsEntered = firstNameEntry.getText().trim();
c= firstNameAsEntered.charAt(0);
firstNameAsEntered= Character.toUpperCase(c) + firstNameAsEntered.substring(1);
System.out.println(firstNameAsEntered);
if (firstNameAsEntered.length() == 0)
System.out.println("First name is required");
}
});
return firstNameEntry;
} // end private JTextField getFirstNameEntry()