第5周:字体设置

来源:互联网 发布:有什么好听的网络歌曲 编辑:程序博客网 时间:2024/05/22 06:29
/**   * 功能:书中(例 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;}

实验结果如图:


0 0
原创粉丝点击