私がJFormattedTextFieldこのようなものを持っていたら
MaskFormatter formatter = new MaskFormatter("#,#");
JFormattedTextField textField = new JFormattedTextField(formatter);
変数がある場合
int x = 0;
int y = 0;
xテキストフィールドの最初の数値を に保存し、2 番目の数値をに保存するにはどうすればよいyですか?
私がJFormattedTextFieldこのようなものを持っていたら
MaskFormatter formatter = new MaskFormatter("#,#");
JFormattedTextField textField = new JFormattedTextField(formatter);
変数がある場合
int x = 0;
int y = 0;
xテキストフィールドの最初の数値を に保存し、2 番目の数値をに保存するにはどうすればよいyですか?
マスクは、内部値の格納方法を変更しません。それを表現/入力する方法を伝えるだけです。
.getText()したがって、選択した形式で文字列を返すがまだあります。その文字列 ( split(), StringTokenizer) を適切に処理します。
,最初と 2 番目の数字が のカンマの両側にあると仮定すると、次のJFormattedTextFieldように実行できます。
String[] numbers = textField.getText().split(",");
int x = Integer.parseInt(numbers[0]);
int y = Integer.parseInt(numbers[1]);