• 设置字体


    package result;

    import java.awt.*;
    import javax.swing.*;
    class MyCanvas extends Canvas{
    String[] FONTS = {"Dialog","DialogInput","Monospaced","Serif","ScanSerif"};
    String TEXT = "一个逻辑字体的示例";
    public MyCanvas() {
    // TODO Auto-generated constructor stub
    setSize(300,300);
    }
    public void paint(Graphics g) {
    for (int i = 0; i < FONTS.length; i++) {
    g.setFont(new Font(FONTS[i],Font.PLAIN,12));
    g.drawString(FONTS[i]+"(plain):"+TEXT,10,20*i+40);
    }
    for (int i = 0; i < FONTS.length; i++) {
    g.setFont(new Font(FONTS[i],Font.BOLD,14));
    g.drawString(FONTS[i]+"(bold,italics):"+TEXT, 10, 20*i+180);
    }
    }
    }
    public class F8 extends JFrame{
    public F8() {
    super("字体");
    setSize(300,300);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    add(new MyCanvas());
    validate();
    }
    public static void main(String[] args) {
    new F8();
    }
    }

    package result;
    import java.awt.*;import javax.swing.*;class MyCanvas extends Canvas{String[] FONTS = {"Dialog","DialogInput","Monospaced","Serif","ScanSerif"};String TEXT = "一个逻辑字体的示例";public MyCanvas() {// TODO Auto-generated constructor stubsetSize(300,300);}public void paint(Graphics g) {for (int i = 0; i < FONTS.length; i++) {g.setFont(new Font(FONTS[i],Font.PLAIN,12));g.drawString(FONTS[i]+"(plain):"+TEXT,10,20*i+40);}for (int i = 0; i < FONTS.length; i++) {g.setFont(new Font(FONTS[i],Font.BOLD,14));g.drawString(FONTS[i]+"(bold,italics):"+TEXT, 10, 20*i+180);}}}public class F8 extends JFrame{public F8() {super("字体");setSize(300,300);setVisible(true);setDefaultCloseOperation(EXIT_ON_CLOSE);add(new MyCanvas());validate();}public static void main(String[] args) {new F8();}}

  • 相关阅读:
    NSURLRequest 使用(网络文摘)
    plist字段列表,很全
    版本控制的发展历史
    UIApplication深入研究
    centos下vi 命令用法
    Oracle Business Intelligence Downloads
    为什么要学习Python语言
    BeginInvoke方法
    利用fsutil命令生成指定大小的文件
    彻底清除Windows共享登录的用户名和密码
  • 原文地址:https://www.cnblogs.com/nanfengnan/p/13678650.html
Copyright © 2020-2023  润新知