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

相关文章:

  • 2021-05-25
  • 2021-04-22
  • 2021-06-09
  • 2021-10-30
  • 2021-06-12
  • 2021-12-15
猜你喜欢
  • 2022-02-11
  • 2021-07-31
  • 2022-12-23
  • 2021-07-28
  • 2021-08-11
  • 2021-12-12
  • 2021-10-15
相关资源
相似解决方案