Created
April 8, 2023 05:22
-
-
Save kishida/8f396b53382693be9559281c68f3fef7 to your computer and use it in GitHub Desktop.
袋文字の描画
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package neoki.slm; | |
import java.awt.*; | |
import javax.swing.*; | |
public class FukuroMojiDrawer extends JPanel { | |
@Override | |
protected void paintComponent(Graphics g) { | |
super.paintComponent(g); | |
Graphics2D g2d = (Graphics2D) g; | |
Font font = new Font("MS Mincho", Font.PLAIN, 48); // 適切な書体を選択してください。 | |
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); | |
g2d.setFont(font); | |
// 文字の縁取り | |
g2d.setColor(Color.BLACK); | |
g2d.setStroke(new BasicStroke(5)); // 縁取りの太さを調整 | |
g2d.draw(font.createGlyphVector(g2d.getFontRenderContext(), "あ") | |
.getOutline(50, 50)); | |
// 文字本体 | |
g2d.setColor(Color.WHITE); | |
g2d.drawString("あ", 50, 50); | |
} | |
public static void main(String[] args) { | |
SwingUtilities.invokeLater(() -> { | |
JFrame frame = new JFrame("FukuroMojiDrawer"); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
frame.add(new FukuroMojiDrawer()); | |
frame.setSize(200, 200); | |
frame.setVisible(true); | |
}); | |
} | |
} |
Author
kishida
commented
Apr 8, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment