通过java画一个大风车

上传人:pu****.1 文档编号:484748018 上传时间:2022-11-08 格式:DOC 页数:15 大小:99KB
返回 下载 相关 举报
通过java画一个大风车_第1页
第1页 / 共15页
通过java画一个大风车_第2页
第2页 / 共15页
通过java画一个大风车_第3页
第3页 / 共15页
通过java画一个大风车_第4页
第4页 / 共15页
通过java画一个大风车_第5页
第5页 / 共15页
点击查看更多>>
资源描述

《通过java画一个大风车》由会员分享,可在线阅读,更多相关《通过java画一个大风车(15页珍藏版)》请在金锄头文库上搜索。

1、今天的作业我做的是画一个风车:运行结果:Ud大风车1首先:写个Point类:(作用作为风车的中点)package com.huang.exam;/*author黄燕斌version 1.0since 2013 - 05-28*/public class Point privatedoublex;privatedoubley;/*构造器*/publicPoi nt()/* *构造器 * paramx * paramy */publicPoint( double x, double y)this.x = x;this.y = y;/*return X*/public double getX() r

2、eturn x;/* paramx X*/public void setX( int x) this . x = x;* return Y*/public double getY() return y;paramy Y*/public void setY( int y) this . y = y;2.写一个风车 Windmill类package com.huang.exam;import java.awt.Color;import java.awt.Graphics;风车author 黄versio n 1.0since 2013 - 05-28*/public class Windmill

3、privatePoi ntcenterprivate int radius ;privateColorcolorpublic Win dmill()构造器paramce nterparamradiusparamcolor*/radius,Colorpublic Win dmill(Poi ntcen ter,intcolor)this.radius=radius;this.center=cen ter;this.color =color;public Color getColor() return color ;public void setColor(Color color) this .

4、color = color;public Point getCe nter() returncenter ;public void setCenter(Point center) this . center = center;public int getRadius() return radius ;/*public void setRadius( int radius) this . radius = radius;画风车public*/paramgvoid draw(Graphics g) /*通过计算出风车10点的位置*/int arrayX = new int 10;int array

5、Y = new int 10;Pointpl = newPoint( center .getX(),center .getY()+radius );Pointp3=newPoint( center .getX()+Math. cos(18*Math. PI/180)* radius , c enter .getY()+Math.sin (18*Math. PI /180)* radius );Pointp5=newPoint( center .getX()+Math. cos (54*Math. PI /180)* radius , c enter .getY()-Math.sin (54*M

6、ath. PI /180)* radius );Pointp7=newPoint( center .getX()-Math. cos (54*Math. PI /180)* radius , c enter .getY()-Math.sin (54*Math. PI /180)* radius );Pointp9=newPoint( center .getX()-Math. cos (18*Math. PI /180)* radius , c enter .getY()+Math.sin (18*Math. PI /180)* radius );double T = 0.3819;Pointp

7、2=newPoint( center .getX(), center .getY()-T*radius );Poi ntp4=newPoint( center .getX()-Math. cos (18*Math. PI /180)*T* radius,center .getY()-Math.sin (18*Math. PI/180)*T* radius );Pointp6=newPoint( center .getX()-Math. cos (54*Math. PI /180)*T* radius ,center .getY()+Math.sin (54*Math. PI /180)*T*

8、radius );Pointp8=newPoint( center .getX()+Math. cos (54*Math. PI /180)*T* radius ,center .getY()+Math.sin (54*Math. PI /180)*T* radius );Pointp10=new,center .getY()-Math.Point( center .getX()+Math. cos (18*Math. PI /180)*T* radiussin (18*Math. PI/180)*T* radius );,center .getY()-Math.sin (18*Math. P

9、I/180)*T* radius );arrayX0=( array Y0=( arrayX1=( arrayY1=( arrayX2=( array Y2=( arrayX3=( array Y3=( arrayX4=( arrayY4=( arrayX5=( array Y5=( int )p1.getX();int )p1.getY();int )p2.getX();int )p2.getY();int )p3.getX();int )p3.getY();int )p4.getX();int )p4.getY();int )p5.getX();int )p5.getY();int )p6

10、.getX();int )p6.getY();,center .getY()-Math.sin (18*Math. PI/180)*T* radius );arrayX 6=( array Y6=( arrayX7=( array Y7=( arrayX8=( array Y8=( arrayX9=( array Y9=( g.setColor(int )p7.getX();int )p7.getY();int )p8.getX();int )p8.getY();int )p9.getX();int )p9.getY();int )p10.getX();int )p10.getY();colo

11、r );g.drawPolygo n( arrayX, array Y, 10)3.写一个 CompantPanel 继承 JPanelpackage com.huang.exam;import java.awt.Color;import java.awt.Graphics;import javax.swing.JPanel;public class CompantPanelextends JPanel public void paintComponent(Graphics g) blue );Poi nt p = new Poi nt(250,200);Win dmill fs =new W

12、in dmill(p,200,Color.fs.draw(g);4.main 类package com.huang.exam;import javax.swing.JFrame;public class Main public static void main(String args) JFrame jFrame = new JFrame(大风车); jFrame.setSize(500,500);jFrame.setLocationRelativeTo(null );Compa ntPa nel cp = new Compa ntPa nel(); jFrame.add(cp);jFrame.setVisible( true );

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 资格认证/考试 > 自考

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号