第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; }
实验结果如图:
相关文章推荐
- 第5周作业-字体设置——略修改成简单文字编辑器
- 第5周作业-字体设置
- 第5周作业-字体设置
- 第5周作业-字体设置
- 第5周作业-字体设置
- 第5周作业-字体设置
- 第5周作业-字体设置
- 第5周作业-字体设置
- 第5周作业-字体设置
- 第5周作业-字体设置
- 第5周作业-字体设置
- richtextbox中如何实现下面这段文字的字体颜色设置?
- Setting color and font attribute for individual items (单独设置CTreectrl 的item 的颜色 与字体)
- myeclipse jsp和java字体设置
- 设置 Intellij 或者 Android Studio 菜单字体大小
- IDEA 字体 编码设置
- (原创)设置APP内的字体
- 设置字体
- 移动端根据屏幕大小自动设置body字体大小
- vs2005 环境的字体和颜色的设置