首页 > Windows开发 > 详细

e591. Drawing Simple Text

时间:2018-09-06 10:33:16      阅读:181      评论:0      收藏:0      [点我收藏+]

See also e575 The Quintessential Drawing Program.

    public void paint(Graphics g) {
        // Set the desired font if different from default font
        String family = "Serif";
        int style = Font.PLAIN;
        int size = 12;
        Font font = new Font(family, style, size);
        g.setFont(font);
    
        // Draw a string such that its base line is at x, y
        int x = 10;
        int y = 10;
        g.drawString("aString", x, y);
    
    
        // Draw a string such that the top-left corner is at x, y
        x = 10;
        y = 30;
        FontMetrics fontMetrics = g.getFontMetrics();
        g.drawString("aString", x, y+fontMetrics.getAscent());
    }

 

Related Examples

e591. Drawing Simple Text

原文:https://www.cnblogs.com/borter/p/9596076.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!