package 绘制图形;
//设置字体样式
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class drawTextFont extends JFrame{
public static void main(String[] args) {
// TODO Auto-generated method stub
new drawTextFont();
}
public drawTextFont() {
// 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 ChangeTextFontPanel());
this.setVisible(true);
this.setBounds(width/4, hight/4, 500,400);
this.setDefaultCloseOperation(3);
}
}
class ChangeTextFontPanel extends JPanel{
public void paint(Graphics g) {
String value = "好好学习丫丫! ! !";
int x = 40;
int y = 50;
// Font(字体类型,风格,字体大小)
/*
* BOLD黑体,ITALIC斜体
*/
Font font = new Font("华文行楷",Font.BOLD+Font.ITALIC,26);
g.setFont(font);
/*
* drawString(文本内容,文本所在X轴,文本所在Y轴)
*/
g.drawString(value, x, y);
value = "一天又一天! ! !";
int x1 = 40;
int y1 = 100;
font = new Font("华文彩云",Font.BOLD,20);
g.setFont(font);
g.drawString(value, x1, y1);
}
}
用java修改字体颜色,画圆角矩形