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

Java第五周作业

2014-04-07 23:44 183 查看
(一)

代码:

package practice.test.demo;

import java.awt.*;
import java.awt.font.*;
import javax.swing.*;

public class FontSet {
/**
* @param args
*/
@SuppressWarnings("deprecation")
public static void main(String[] args) {
// TODO Auto-generated method stub
FontFrame frame = new FontFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}

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 = 140;
}

class FontPanel extends JPanel {
public void paintComponent(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;
};
结果:



(二)

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