mirror of
https://codeberg.org/qg-info-unterricht/zpg-graphentester.git
synced 2026-03-25 04:58:24 +01:00
43 lines
No EOL
936 B
Java
43 lines
No EOL
936 B
Java
package imp;
|
|
|
|
import javafx.scene.control.TextField;
|
|
|
|
public class NumberField extends TextField {
|
|
|
|
@Override public void replaceText(int start, int end, String text) {
|
|
if (text.matches("[0-9.]") || text == "") {
|
|
super.replaceText(start, end, text);
|
|
}
|
|
}
|
|
|
|
@Override public void replaceSelection(String text) {
|
|
if (text.matches("[0-9.]") || text == "") {
|
|
super.replaceSelection(text);
|
|
}
|
|
}
|
|
|
|
public double getDoubleValue() {
|
|
try{
|
|
return Double.parseDouble(this.getText());
|
|
} catch(Exception e) {
|
|
return 0.0;
|
|
}
|
|
}
|
|
|
|
public int getIntValue() {
|
|
try{
|
|
return Integer.parseInt(this.getText());
|
|
} catch(Exception e) {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public void setValue(double v) {
|
|
setText(""+v);
|
|
}
|
|
|
|
public void setValue(int v) {
|
|
setText(""+v);
|
|
}
|
|
|
|
} |