第5周作业-字体设置

来源:互联网 发布:中国电信云计算大数据 编辑:程序博客网 时间:2024/06/06 01:49

代码:

 import java.awt.*; import java.awt.Font.*;import javax.swing.*;public class FontSet {public static void main (String argss[]) { FontFrame frame = new FontFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);  } } class FontFrame extends JFrame { public FontFrame() { setTitle("设置字体"); setSize(WIDTH,HEIGHT); FontPanel panel = new FontPanel();   //将panel加入到Frame Container contentpane = getContentPane(); contentpane.add(panel); } public static final int WIDTH=300; public static final int HEIGHT=400; } class FontPanel extends JPanel { public void pantComponent (Graphics g) { super.paintComponent(g);  //设置字体 Font f =new Font("宋体",Font.BOLD+Font.ITALIC,20); g.setFont(f); //显示文本 g.drawString("java欢迎您!",x,y); } public int x=55; public int y=50;  }                

运行结果:


0 0
原创粉丝点击