Label

Label objects are used to present  text inside a display.

The following function creates a new Label, so you need to save it in a variable (so you can use it later).

Label objects are created using the following functions.

Function Description
Label(text) Create a new label with specified text (string).
Label(text, alignment) Create a new label with specified text (string) and alignment (LEFT, CENTER or RIGHT – default is LEFT).
Label(text, alignment, foregroundColor, backgroundColor) Create a new label with specified text (string), alignment (LEFT, CENTER or RIGHT), foreground color (e.g. Color.BLACK (default), Color.ORANGE or Color(255, 0, 255), using specific RGB values), and background color (same – if omitted, background color defaults to transparent).

For example, a label may be created as follows:

label1 = Label("Hello World!")
d.add(label1, 50, 50)

Once a label has been created, it cannot be resized.  So, you should create it with the widest (possibly blank) string necessary, e.g.,

label1 = Label("                ")   # up to 16 characters

Label objects have the following functions:

Function Description
label1.setText(text) Updates the label’s contents (a string). If provided string is longer than the maximum label size (see above), it will be truncated.
label1.getText() Returns the label’s text (as a string).
label1.setFont() Changes the font used in label1, e.g., Font(“Dialog”, Font.PLAIN, 12), Font(“Serif”, Font.ITALIC, 16), or Font(“TimesRoman”, Font.BOLD | Font.ITALIC, 20).

For more information of fonts, see the Font Java API documentation.

Finally, you may use the following functions:

Function Description
label1.setForegroundColor(color) Changes foreground (text) color to the specified color (e.g. Color.BLACK or Color(255, 0, 255), using specific RGB values).  If the color parameter is omitted, a color selection dialog box will be presented.
label1.getForegroundColor() Returns the current foreground (text) color.
label1.setBackgroundColor(color) Changes background color to the specified color (e.g. Color.BLACK or Color(255, 0, 255), using specific RGB values).  If the color parameter is omitted, a color selection dialog box will be presented.
label1.getBackgroundColor() Returns the current background color.
label1.getX() Returns the x coordinate (in pixels).
label1.getY() Returns the y coordinate (in pixels).
label1.setX(x) Sets the x coordinate (in pixels).
label1.setY(y) Sets the y coordinate (in pixels).
label1.encloses(other) Returns True if label1 encloses other graphics object.
label1.intersects(other) Returns True if label1 intersects other graphics object.
label1.getPosition() Returns the position as an (x, y) tuple.  This is the top-left corner of the box that encloses the label.
label1.setPosition(x, y) Sets the position to x, y.  This is the top-left corner of the box that encloses the label.