indexOfpublic int indexOf(String str)Returns the index within this string of the first occurrence of the specified substring. The integer returned is the smallest value k such that:
this.startsWith(str, k)
is true.Parameters:str - any string.Returns:if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.Throws:NullPointerException - if str is null.
this.startsWith(str, k)
is true.Parameters:str - any string.Returns:if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.Throws:NullPointerException - if str is null.
private class MyKeyAdapter extends KeyAdapter{
public void keyTyped(KeyEvent kevent){
String strValid="0123456789+-.";
int temp;
temp=kevent.getKeyCode();
if(strValid.indexOf(temp)==-1)
kevent.setKeyCode(0);
}
}