First of all I would like to welcome to you to Java Prgoramming Forums. I hope we can help you out
Well here is an example that should get you thinking along the right lines and probably give you a solution. It's not using AWT or anything just commandline for ease. But you can implement it into your example easy enough.
public class FretDancer {
public void checkForInvalidCharacter(String s)
throws CustomFormatException {
for(int i = 0; i < s.length(); i++)
if(!Character.isLetterOrDigit(s.charAt(i)))
throw new CustomFormatException("Invalid Character");
}
public FretDancer(){
String testString = "Hello,";
try {
checkForInvalidCharacter(testString);
} catch (CustomFormatException cfe) { cfe.printStackTrace(); }
}
public static void main(String[] args) {
new FretDancer();
}
}
class CustomFormatException extends java.lang.Exception {
public CustomFormatException(String s){
super(s);
}
}
Just a note instead of using your own custom exception you could use
IllegalArgumentException which would be used in the same way, but you wouldn't need the custom exception class.
Sorry for the slow reply.
Regards,
Chris