package hhxy.Test;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
public class GraphicsFrame extends JFrame{
public GraphicsFrame(){
super("Graphics范例");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(300, 250);
setSize(400,180);
setVisible(true);
}
public void paint(Graphics g){
g.setColor(Color.BLACK);
g.drawLine(0, 35, 100, 35);//画一条直线
g.setColor(Color.RED);
g.drawRect(5, 40, 90, 55);//画空心矩形
g.fillRect(100, 40, 90, 55);//画实心矩形
g.setColor(Color.ORANGE);
g.drawRoundRect(195, 40, 90, 55, 50, 50);//画空心圆角矩形
g.fillRoundRect(290, 40, 90, 55, 20, 20);//画实心圆角矩形
g.setColor(Color.YELLOW);
g.draw3DRect(5, 100, 90, 55, true);//画空心3D矩形
g.fill3DRect(100, 100, 90, 55, true);//画实心3D矩形
g.setColor(Color.GREEN);
g.drawOval(195, 100, 90, 55);//画空心椭圆
g.fillOval(290, 100, 90, 55);//画实心椭圆
}
public static void main(String[] args) {
new GraphicsFrame();
}
}
结果: