设置字体
java.awt.Font类
设置文本的字体(包括字型和字号)
public Font(String name, int style int size)
例:
Font f = new Font(“Dialog”, Font.PLAIN, 14);
1)字体名称: Dialog、DialogInput、Monospaced、Serif、SansSerif
2)字体的风格:Font.BOLD、Font.ITALIC、Font.PLAIN、Font.BOLD+Font.ITALIC
3)字体的大小
setFont(Font f)方法对组件中文本的字体进行设定
java.awt.Color类控制颜色,Color类已包含13个颜色常量
public Color(int r, int g, int b)
public Color(float r1, float g1, float b1)
例:
int r = 255, g = 255, b = 0;
Color myColor = new Color(r, g, b)
设置组件的前景色和背景色
public void setForeground(Color c)——设置前景色
public void setBackground(Color c)——设置背景色
圆弧:
drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
直线
drawLine(int x1, int y1, int x2, int y2)
椭圆
drawOval(int x, int y, int width, int height)
fillOval(int x, int y, int width, int height)
多边形
drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
矩形
drawRect(int x, int y, int width, int height)
fillRect(int x, int y, int width, int height)
圆角矩形
drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
字符串
drawString(String str, int x, int y)
学习完了,是不是so easy!让我们一起练习巩固一下吧。戳这里