Java Graphics_4

package com.han;

import java.awt.Canvas;
import java.awt.Graphics;

import javax.swing.JFrame;

@SuppressWarnings("serial")
public class Graphics_4 extends JFrame {

	public Graphics_4() {
		// TODO Auto-generated constructor stub
		Canvas canvas = new Canvas() {
			@Override
			public void paint(Graphics g) {
//				super.paint(g); // for the one containing children components, this is necessary.
				int[] xPoints = { 10, 50, 10, 50 };
				int[] yPoints = { 10, 10, 50, 50 };
//				int nPoints = 3;
				int nPoints = 4;
				g.drawPolygon(xPoints, yPoints, nPoints);
				
				int[] xPoints2 = { 60, 100, 100, 60 };
				int[] yPoints2 = { 10, 10, 50, 50 };
				int nPoints2 = 4;
				g.drawPolygon(xPoints2, yPoints2, nPoints2);
				
				g.drawRect(110, 10, 40, 40);
				g.drawRoundRect(160, 10, 40, 40, 10, 10);
			}
		};
		this.add(canvas); // add()方法最早出现在Container中,所以我们无法在Canvas中添加组件。 
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Graphics_4 frame = new Graphics_4();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setTitle("Draw polygon");
		frame.setSize(300, 200);
		frame.setVisible(true);
	}

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值