📄 showfonts.java
字号:
// Fig. 2.6_02: ShowFonts.java
// 显示系统中可用的字体
// 引入相关的包
import java.awt.*; // 引入 java.awt包中所有的类
import javax.swing.*; // 引入 javax.swing包中所有的类
public class ShowFonts extends JApplet
{
String text = "Welcome Java Web chart programming!" ;
GraphicsEnvironment e ;
Font[] fonts ;
public void init()
{
e = GraphicsEnvironment.getLocalGraphicsEnvironment();
fonts= e.getAllFonts();
}
// 在applet上绘制文本
public void paint(Graphics g)
{
// 调用父类的 paint 方法
super.paint(g);
for (int i = 0; i< fonts.length - 1 ; i++)
{
g.setFont(new Font(fonts[i].getName(), Font.PLAIN, 15));
g.drawString("Font name:" + fonts[i].getName() +
", 效果:" + text, 40, 30 + 20 * i);
}
} // paint 方法结束
} // ShowFonts 类结束
/**************************************************************************
* (C) Copyright 2004-2005 by Jingkui Zhong(钟京馗) and Huan Tang(唐桓). *
* All Rights Reserved. *
* *
* DISCLAIMER: The authors of this code have used their *
* best efforts in preparing the code. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these codes. The authors *
* shall not be liable in any event for incidental or consequential *
* damages in connection with, or arising out of, the furnishing, *
* performance, or use of these programs. *
**************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -