All Packages Class Hierarchy This Package Previous Next Index
Class BreezyGUI.Format
java.lang.Object
|
+----BreezyGUI.Format
- public class Format
- extends Object
The class Format contains methods to format data that are left-justified,
right-justified, or centered within a given number of columns.
-
Format()
-
-
justify(char, char, int)
- Converts a character to a string and returns it formatted formatted according to the justification type and the
specified width.
-
justify(char, double, int, int)
- Converts a double to a string and returns it formatted according to the justification type and the
specified width and precision.
-
justify(char, long, int)
- Converts a long to a string and returns it formatted formatted according to the justification type and the
specified width.
-
justify(char, String, int)
- Returns a string that is formatted according to the justification type and the
specified width.
Format
public Format()
justify
public static String justify(char leftRight,
String str,
int width)
- Returns a string that is formatted according to the justification type and the
specified width. If the width is less than the length of the string, returns
a string of stars (*) whose length equals the width.
- Parameters:
- leftRight - the type of justification ('l', 'c', or 'r').
- str - the string to be formatted.
- width - the number of columns in which the string is placed.
Examples:
String right = Format.justify('l', "Hi", 4);
String left = Format.justify('c', "Hi", 4);
String center = Format.justify('r', "Hi", 4);
String noChange = Format.justify('r', "Hi", 2);
String tooFew = Format.justify('r', "Hi", 1);
left now refers to "Hi "
center now refers to " Hi "
right now refers to " Hi"
noChange now refers to "Hi"
tooFew now refers to "**"
justify
public static String justify(char leftRight,
char ch,
int width)
- Converts a character to a string and returns it formatted formatted according to the justification type and the
specified width.
- Parameters:
- leftRight - the type of justification ('l', 'c', or 'r').
- ch - the character to be formatted.
- width - the number of columns in which the character is placed.
justify
public static String justify(char leftRight,
long x,
int width)
- Converts a long to a string and returns it formatted formatted according to the justification type and the
specified width.
- Parameters:
- leftRight - the type of justification ('l', 'c', or 'r').
- x - the long integer to be formatted.
- width - the number of columns in which the integer is placed.
justify
public static String justify(char leftRight,
double x,
int width,
int precision)
- Converts a double to a string and returns it formatted according to the justification type and the
specified width and precision. The decimal point occupies a column in the formatted number.
- Parameters:
- leftRight - the type of justification ('l', 'c', or 'r').
- x - the number to be formatted.
- width - the number of columns in which the number is placed.
- precision - the number of places of precision retained in the formatted number.
Examples:
String fourPlaces = Format.justify('r', 3.1416, 7, 4);
String threePlaces = Format.justify('r', 3.1416, 7, 3);
String twoPlaces = Format.justify('r', 3.1416, 7, 2);
String noPlaces = Format.justify('r', 3.1416, 7, 0);
fourPlaces now refers to " 3.1416"
threePlaces now refers to " 3.142"
twoPlaces now refers to " 3.14"
noPlaces now refers to " 3"
All Packages Class Hierarchy This Package Previous Next Index