A lopp can be used to display all through all the characters and the isDefined() method of the Character class can be used to determine if a given character is a valid Unicode character or not
for (int i=0; i<=Integer.MAX_VALUE; i++)
{
if (Character.isDefined(i))
{
System.out.println(Integer.toHexString(i)+": "+
new String(Character.toChars(i)));
}
}
written by objects
\\ tags: character, hex, unicode
To switch focus to a text field (or any component actually) just call the target components requestFocusInWindow() method.
textField.requestFocusInWindow();
NB. There is also a requestFocus() method but it’s behavior is platform dependent and thus it’s use is discouraged.
written by objects
\\ tags: component, focus, JTextField
Standard rounding provided by BigDecimal and DecimalFormat rounds to the nearest 0 or 1. If you instead want to round to 0, 1 or 0.5 then you need to do a little work
For example to round up to 4 decimal places to the nearest 0, 1, or .5 you could use the following code.
BigDecimal bd = new BigDecimal((d * 2.0) + 0.0005)
.setScale(3, BigDecimal.ROUND_HALF_UP);
bd = new BigDecimal(bd.doubleValue()/2.0)
.setScale(4, BigDecimal.ROUND_HALF_UP);
String rounded = bd.toString();
written by objects
\\ tags: BigDecimal, DecimalFormat, round, rounding