java字体设计
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class newFont {
public static void main(String[] args) {
drawFrame1 jf = new drawFrame1();
jf.setVisible(true );
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class drawFrame1 extends JFrame
{
public drawFrame1()
{
this .setTitle("字体" );
this .setSize(600 , 400 );
this .setLocationRelativeTo(null );
this .setResizable(false );
/**
* 为框架添加内容
* 添加一个Panel面板
*/
drawPanel1 jp = new drawPanel1();
this .add(jp);
}
}
class drawPanel1 extends JPanel
{
public drawPanel1()
{
this .setBackground(Color.yellow);
}
public void paintComponent(Graphics g)
{
super .paintComponent(g);
Graphics2D g1 = (Graphics2D) g;
this .draw(g1);
}
private void draw(Graphics2D g) {
g.setPaint(Color.BLACK);
Font f = new Font("华文行楷" ,Font.BOLD,30 );
g.setFont(f);
g.drawString("你好中国" , 30 , 40 );
}
}
/**
//显示系统自带字体
import java.awt.*;
public class ListFonts
{
public static void main(String[] args)
{
String[] fontNames = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getAvailableFontFamilyNames();
for (int i = 0; i < fontNames.length; i++)
System.out.println(fontNames[i]);
}
}
*/