程序运行界面如下:

代码如下:
//宋体,隶书,幼圆,华文彩云,华文行楷,楷体_GB2312,黑体,方正舒体,华文细黑,华文仿宋 import java.awt.*; import javax.swing.*;
public class FontShow extends JFrame { private String font[] = {"宋体","隶书","幼圆","华文彩云","华文行楷", "楷体_GB2312","黑体","方正舒体","华文细黑", "华文仿宋"};//定义字体数组 private Color[] colour = {Color.RED,Color.ORANGE,Color.YELLOW,Color.GREEN, Color.BLUE,Color.CYAN,Color.MAGENTA,Color.RED, Color.ORANGE,Color.YELLOW};//定义颜色数组
// set window's title bar and dimensions public FontShow() { super( "Showing fonts" );
setSize( 420, 600 ); setVisible( true ); }
// display Strings in different fonts and colors public void paint( Graphics g ){ // call superclass's paint method super.paint( g ); for(int i=0; i<font.length;i++){// g.setColor( colour{i} ); g.setFont( new Font( font{i}, Font.BOLD, 12+3*i ) ); g.drawString("" + (12+3*i) + "号" + g.getFont().getName(), 20, 50+i*50 ); } //显示说明 g.setColor(Color.BLACK); g.setFont(new Font("宋体",Font.BOLD,12)); g.drawString("以上颜色根据‘红橙黄绿蓝锭紫的顺序渐变",20,570); } public static void main(String[] args){ FontShow application = new FontShow(); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); //关闭按钮事件 } }
| 上网速度更快更爽、更安全下载使用Firefox火狐浏览器
|
|
|