日期:2014-05-20 浏览次数:20970 次
package org.test;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MyFrame extends JFrame{
public MyFrame(){
MyPanel p = new MyPanel();
add(p);
setSize(400,400);
}
public static void main(String[] args) {
MyFrame f = new MyFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
class MyPanel extends JPanel{
public void paintComponent(Graphics g){
g.setFont(new Font("宋体",Font.BOLD,10)); //改变字体大小
g.drawString("Hello world!!!", 20, 20);
g.setFont(new Font("宋体",Font.BOLD,30));
g.drawString("Hello world!!!", 40, 40);
g.setFont(new Font("宋体",Font.BOLD,60));
g.drawString("Hello world!!!", 60, 60);
}
}
}
------解决方案--------------------
http://blog.csdn.net/xiazdong/article/details/6918641
------解决方案--------------------
1楼正解,