No, you can't. The line: int LengthInt = Length.getText();
tries to put a String Object (Length.getText()
) into an primitive tipe (int
).
There is no implicit conversion from String to integer in Java, because a String can contain anything (like "abc", for example) that is not directly convertible to a number.
Also, the first two lines should be changed to this: JFormattedTextField Length = new JFormattedTextField(NumberFormat.getIntegerInstance());
Instantiate the JFormattedTextField with the NumberFormat instead of Number.