您的位置:首页 > 编程语言 > Java开发

第5周:字体设置

2014-04-01 20:07 274 查看
/**
* 功能:书中(例 9-3)
* 作者:郑楷山
* 时间:2014-04-01
* 博客:blog.csdn.net/kshanz
* */
import java.awt.*;
import java.awt.font.*;
import javax.swing.*;
public class FontSet {

public static void main(String[] args) {
FontFrame frame = new FontFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class FontFrame extends JFrame{
public FontFrame(){
setTitle("设置字体");
setSize(300, 140);
FontPanel panel = new FontPanel();
TextField tf = new TextField (3);
tf.setText(panel.f.getName());
panel.add(tf);
Container contentPane = getContentPane();
contentPane.add(panel);
}
}
class FontPanel extends JPanel{
Font f = new Font("宋体", Font.BOLD+Font.ITALIC,20);
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setFont(f);
g.drawString("Java 欢迎您!", x, y);
}
public int x = 55;
public int y = 50;
}

实验结果如图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java 例子