AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
drawString (Object obj, String str, Number x, Number y [, double alpha]) yoix.graphics
 
Prints the characters in str starting at the point (x,y) in obj, which must be an Image or a drawable component (i.e., a Swing or AWT component, like a JCanvas, JFrame, or Canvas, that supports a paint function). The text is drawn using the font and foreground color selected by the Graphics object associated with obj, and is painted using the optional alpha argument, which should be a number between 0.0 and 1.0, as the alpha value. Omitting alpha or supplying a value of 1.0 are equivalent.
 
 Example:   The program,
import yoix.*.*;

final double SHADOW = 72.0/36;
final String FONT = "Helvetica-plain-14";


JFrame frame = {
    FlowLayout layoutmanager = {
        int vgap = 72;
    };

    Array layout = {
        new JCanvas {
            Color background = Color.gray;
            int   state = FALSE;

            String text = "Testing";

            Insets border = {
                double left = SHADOW;
                double top = SHADOW;
                double right = SHADOW;
                double bottom = SHADOW;
            };

            Graphics graphics = {
                String font = FONT;
                Color  foreground = Color.red;
            };

            Dimension size = {
                double height = graphics.font.height + 10*SHADOW;
                double width = stringWidth(graphics.font, text) + 10*SHADOW;
            };

            paint(clip) {
                Font   font = graphics.font;
                double x = (size.width - stringWidth(this, text))/2;
                double y = (size.height + font.height)/2 - font.descent;

                drawString(this, text, x, y);
            }

            actionPerformed(ActionEvent e) {
                printf("Carry out action\n");
            }
        },
    };
};

frame.visible = TRUE;
sleep(5);
exit(0);
is a rather complicated example that shows how to build a custom button with a centered text label out of a canvas. A fancier button that displays an image rather than a text label is just as easy.
 
 See Also:   clearRect, copyArea, drawArc, drawImage, drawLine, drawOval, drawPolygon, drawPolyline, drawRect, drawRoundRect, fillArc, fillOval, fillPolygon, fillRect, fillRoundRect, pointInPolygon, pointInRect, rectContainsRect, rectIntersectionRect, rectIntersectsRect, rectUnionRect, stringBounds, stringWidth

 

Yoix is a registered trademark of AT&T Inc.