1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| package test;
import java.awt.*;
import java.awt.font.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.*;
public class TestMusicFont extends JPanel {
private Font f1 = new Font("Dialog", Font.PLAIN, 25);
private Font f2;
private Font f3 = new Font("MusicalSymbols", Font.PLAIN, 25); //When installed as a system font.
public TestMusicFont() {
try {
InputStream str = getClass().getClassLoader().getResourceAsStream("Musical.ttf");
try {
f2 = Font.createFont(Font.TRUETYPE_FONT, str);
f2 = f2.deriveFont(Font.PLAIN, 25f);
}
finally {
str.close();
}
}
catch (FontFormatException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
} //constructeur
public static void main(String ...args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(new TestMusicFont(), BorderLayout.CENTER);
//frame.setSize(400, 300);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setVisible(true);
}
});
} //main
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Insets insets = getInsets();
Dimension size = getSize();
int width = size.width - (insets.left + insets.right);
int height = size.height - (insets.top + insets.bottom);
Graphics2D g2d = (Graphics2D) g.create(insets.left, insets.top, width, height);
try {
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.setFont(f1);
g2d.drawString("Z azertrytyuiopmlkjgfdsq AZEZETRYUPMLJHGFDSQCXVBN1234567890&é'(-è_ç", 10, 50);
g2d.setFont(f2);
g2d.drawString("Z azertrytyuiopmlkjgfdsq AZEZETRYUPMLJHGFDSQCXVBN1234567890&é'(-è_ç", 10, 100); // Render squares.
g2d.setFont(f3);
g2d.drawString("Z azertrytyuiopmlkjgfdsq AZEZETRYUPMLJHGFDSQCXVBN1234567890&é'(-è_ç", 10, 150); // Render squares.
//
g2d.setFont(f1);
g2d.drawString("\uF026\uF08D\uF082\uF0C4\uF0E5\uF0A7", 10, 200);
g2d.setFont(f2);
g2d.drawString("\uF026\uF08D\uF082\uF0C4\uF0E5\uF0A7", 10, 250);
g2d.setFont(f3);
g2d.drawString("\uF026\uF08D\uF082\uF0C4\uF0E5\uF0A7", 10, 300);
}
finally {
g2d.dispose();
}
} //paint
} |
Partager