Re: Applet to JFrame GUI
IchBin wrote:
ButtonNovice wrote:
else if (dotpos < numString.length() - 2)
return numString.substring(0, dotpos + 3); // `.'+ 2 digits
else
return numString + "0"; // Assume only 1 fraction digit
}
You have an extra bracket below, just delete it.
=====> }
I suggest putting } and { in everywhere.
if (dotpos < 0) {
// Whole number.
return numString;
} else if (dotpos < numString.length() - 2)
// Excess fraction digits.
// 3 represents '.' + 2 digits.
return numString.substring(0, dotpos + 3);
} else {
// Assume only 1 fraction digit.
return numString + "0";
}
Also:
o double isn't a good type to represent money. Use, say, BigDecimal or
long number of cents.
o Rounding may make your code a cent out.
o Your code will break for some formats of toString(double).
o If you want your code to work both as an Applet and an application,
I suggest moving common code out into a separate class. The Applet and
application class should be very small and do the minimum necessary. In
fact, I suggest you do this anyway.
o There is rarely any point in subclassing JFrame.
Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/