⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fontcolor.java

📁 《Java程序设计与应用》-张仕斌-源程序 《Java程序设计与应用》-张仕斌-源程序
💻 JAVA
字号:
//FontColor.java
import java.awt.*;
import javax.swing.*;

public class FontColor extends JFrame {
	Color[] colors = null;
	String[] fontNames = null;
	
	public FontColor() {
		super("Font Color Test");
		colors = new Color[2];
		colors[0] = new Color(255,0,0); //红色
		colors[1] = new Color(0,0,255); //蓝色
		
		GraphicsEnvironment gl = GraphicsEnvironment.getLocalGraphicsEnvironment();
		fontNames = gl.getAvailableFontFamilyNames(); //取得所有可用字体名称
	}
	
	public void paint(Graphics g) {
		Font newFont = null;
		for (int i = 0; i < fontNames.length && i < 10 ; i++ ) {
			newFont = new Font(fontNames[i],Font.PLAIN,18); //生成字体对象
			g.setFont(newFont);           //设置当前字体
			g.setColor(colors[ i % 2]);   //设置当前颜色
			g.drawString(fontNames[i] , 10 , 50 + i * 21); 
		}
	}
	
	public static void main(String[]args) {
		FontColor fc = new FontColor();
		fc.setSize(500,400);
		fc.setDefaultCloseOperation(EXIT_ON_CLOSE);
		fc.setVisible(true);
	}
}
			
	

⌨️ 快捷键说明

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