fontdemo.java

来自「Java the UML Way 书中所有源码」· Java 代码 · 共 30 行

JAVA
30
字号
/*
 * FontDemo.java   E.L. 2001-08-30
 */

import javax.swing.*;
import java.awt.*;

public class FontDemo extends JApplet {
  public void init() {
    Container content = getContentPane();
    Drawing aDrawing = new Drawing();
    content.add(aDrawing);
  }
}

class Drawing extends JPanel {
  public void paintComponent(Graphics window) {
    super.paintComponent(window);
    window.drawString("This is written with the default font", 40, 60);
    Font theFont = new Font("SansSerif", Font.BOLD, 16);
    window.setFont(theFont);
    window.drawString("This is written with the " + theFont.getName() + " font", 40, 100);
    theFont = new Font("Monospaced", Font.ITALIC, 16);
    window.setFont(theFont);
    window.drawString("This is written with the " + theFont.getName() + " font", 40, 140);
    theFont = new Font("Dialog", Font.BOLD + Font.ITALIC, 16);
    window.setFont(theFont);
    window.drawString("This is written with the " + theFont.getName() + " font", 40, 180);
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?