日期:2014-05-20  浏览次数:20755 次

用java画板drawString的字,可以改变大小吗?
老师让花一个钟表出来,例如这个语句,g.drawString("12", xCenter - 5, yCenter - clockRadius + 12);,但是画出来的12太小了,有办法改变大小吗?

------解决方案--------------------
Java code

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楼正解,