一、组件的颜色
1.public void setBackground(Color c);
2.public void setForeground(Color c);
3.public Color getBackground(Color c); //获取组件的背景色
4.public Color getForeGround(Color c); //获取组件的前景色
Color类是Java.awt包中的类。用Color类的构造方法public Color(int red,int green,int blue)可以创建一个颜色对象,三个颜色值取值都在0-255之间。Color类还有red,blue,green,orange,cyan,yellow,pink等静态常量。
二、组件的字体
1.public void setFont(Font f);
2.public Font getFont(Font f);
3.public Font(String name,int style,int size);
1) name:字体名称,如果系统中无该字体,则取默认的字体名字。
2) style:字体的式样,取值是一个整数,其有效取值为:
Font.BOLD,Font.PLAIN,Font.ITALIC,
Font.ROMAN_BASELINE,Font_CENTER_BASELINE,Font.HANGING_BASELINE,
FOnt.TRUETYPE_FONT
3) size:字体的大小,单位是磅(如5号字体是12磅)。
4.获取系统中有哪些字体名字可用的方法:
GraphicsEnvironment ge=GraphicsEnvironment getLocalGrphicsEnvironme
String fontName[]=ge.getAvailableFontFamilyNa
三、组件的大小与位置
1.public void setSize(int width,int height);
2.public void setLocation(int x,int y);
3.public Dimension getSize();
4.public Point getLocation(int x,int y);
5.public void setBounds(int x,int y,int width,int height);
6.public Rectangle getBounds();
Rectangle对象的常用方法:
1) Rectangle(int x,int y,int width,int height);
2) public boolean intersects(Rectangle rect);
3) public boolean contains(int x,int y);
4) public boolean contains(int x,int y,int width,int height);//矩形是否包含参数指定的矩形
5) public boolean contains(Rectangle rect); //同上
6) public Rectangle intersection(Rectangle rect);
7) public Rectangle union(Rectangle rect);
四、组件的激活与可见性
1.public void setEnabled(boolean b);
2.public boolean isEnabled();
3.public void setCisible(boolean b);
4.public boolean isVisible();
五、组件上的光标
1.public void setCursor(Cursor c);
2.Cursor c=new Cursor(Cursor.HAND_CURSOR);
3.Cursor c=Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); //直接获得一个光标对象
六、paint方法与repaint方法
public void paint(Graphics g);
repaint方法首先清除paint方法所画内容,然后再调用paint方法。