Java 绘图

package expression;

import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;

import javax.swing.JFrame;

public class Demo extends JFrame{
	
	public Demo() {
		super();
		init();
		add(new mycanvas());
	}
	private void init() {
		this.setTitle("绘制几何图形");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setSize(500,300);
	}
	public static void main(String[] args) {
		new Demo().setVisible(true);
	}
	private class mycanvas extends Canvas {

	 public  void paint(Graphics g) {
		// TODO Auto-generated method stub
		Graphics2D g2 = (Graphics2D) g;
		g2.drawOval(5, 5, 100, 100);
		g2.fillRect(15, 15, 80, 80);
		
		Shape shape1 = new Rectangle2D.Double(100, 5, 100, 100);//矩形对象
		g2.fill(shape1);
		
		int x[]={250,300,250,300};
		int y[]={130,130,200,200};
		g2.drawPolygon(x,y,4);//多边形  第三个参数是边数 第一二个参数是 边数横,纵坐标
		
		
		
	}
	
}
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券