1

I am making a music app using Graphics 2D, and I have managed to draw the stave and the music notes. I am now trying to draw a G-clef

Image of G-clef

and an F-clef

Image of F-clef

If there is another possible way to do it, I will appreciate.

NB: I have looked around for two days and I have seen questions that are similar but I haven't yet seen a solution.

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
Josiah
  • 118
  • 10

1 Answers1

2

Using points and curves is not the best way. Thanks to @David, I found out that unicodes work best. To use a unicode in printing a string,

import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JFrame;

public class UnicodeText {
public static void main(String[] args) {
JFrame f = new JFrame() {
  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
        RenderingHints.VALUE_ANTIALIAS_ON);

    Font font = new Font("Bravura", Font.PLAIN, 32);

    g2.setFont(font);
    g2.drawString("\uD834\uDD1E", 40, 80);// Gclef
    g2.drawString("\uD834\uDD22", 40, 80);// Fclef
  }
};
f.setSize(200,200);
f.setVisible(true);
}
}

Download the "bravura" font here and find the unicode standard chart here

Hope it helps someone.

Josiah
  • 118
  • 10