hi ^_^
I want to write a code to set an (error) text in the Jtextfiled if the number contains more than 1 dot (eventHandling)! but my code actually didn't concatinate with the next digits I've enterded ,for example:(2. ) and stop !
so what is the right solution ?!!
this is the part of (eventHandling for the numbers and the dot )
else if (".0123456789".contains(event)) {
numberButton(event, out);
and this is the part of code for (the conditions of the dot and the numbers )
private void numberButton(String number, String out) {
String s = T.getText();
int count=0;
if (!s.isEmpty()) {
char c[] = new char[10];
c = s.toCharArray();
boolean a = true;
for (int m = 0; m < c.length; m++) {
if (!Character.isDigit(c[m])) {
a = false;
break;
}
}
if (!a) {
for (int n=0 ;n<s.length();n++){
if (s.indexOf(n)=='.'){
count++;
}
if (count > 1){
T.setText("Error");
break;
}
else if(count==1) {
T.setText(T.getText() + number);
}
}//for
}
else {
int num = Integer.parseInt(out);
String result_string = Integer.toString(num);
T.setText(result_string + number);
}
}
else {
T.setText(number);
}
}