用java修改字体颜色,画圆角矩形

package 绘制图形;
//改字体颜色,画圆角矩形
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class TextColorFrame extends JFrame{

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new TextColorFrame();

    }
    public TextColorFrame() {
        // TODO Auto-generated constructor stub
        Toolkit kit = java.awt.Toolkit.getDefaultToolkit();
        Dimension screen = kit.getScreenSize();
        int width = screen.width;
        int hight = screen.height;
        this.setTitle("改字体颜色");
        this.add(new TextColorPanel());
        this.setVisible(true);
        this.setBounds(width/4, hight/4, 300,200);
        this.setDefaultCloseOperation(3);
    }

}
class TextColorPanel extends JPanel{
    public void paint(Graphics g) {
        String value = "我除了学习啥都不会--------";
        int x = 60;
        int y = 60;
        Color color = new Color(255, 0, 0);
        g.setColor(color);
        g.drawString(value, x, y);
        value = "只好搞学习了";
        x = 140;
        y = 100;
        color = new Color(0, 0, 255);
        g.setColor(color);
        /*
         * 前两个坐标表示矩形的起始坐标,
         * 中间两个是矩形的长宽,最后两个是弧形的长宽
         */
        g.drawString(value, x, y);
        color = Color.ORANGE;
        g.setColor(color);
        g.drawRoundRect(40, 30, 200, 100, 40, 40);
        g.drawRoundRect(45, 35, 190, 90, 36, 36);
    }
    
}

修改字体的颜色.png

不得不说java画图真的是扎眼啊!!!!

你可能感兴趣的:(用java修改字体颜色,画圆角矩形)