zoukankan      html  css  js  c++  java
  • applet main共存 五角星和五面形

    import javax.swing.*;
    
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.geom.Point2D;
    import java.util.Vector;
    
    public class DrawStar extends Applet {
        Vector<Point2D.Double> points = new Vector<Point2D.Double>();
        Polygon poa,pob;
        double r = 100;
        double n = r+50;
        public DrawStar(){
            computerPoints(5);
        }
        public void init(){
            computerPoints(5);
            
        }
        private void computerPoints(int n){
            
            double pi = 3.14159265;
            points.add(new Point2D.Double(0,r));
            for(int i=1;i<n;i++) {
                double x = r*Math.sin(2*pi*i/n);
                double y = r*Math.cos(2*pi*i/n);
                points.add(new Point2D.Double(x,y));
            
            }
            
        }
        public void paint(Graphics g) {
            fillPolygonA();
            fillPolygonB();
            g.drawPolygon(poa);
            g.drawPolygon(pob);
        }
        private void fillPolygonA() {
            poa = new Polygon();
            for(int i=0;i<points.size();i++) {
                int x = (int)(points.get(i).getX()+n);
                int y = (int)(points.get(i).getY()+n);
                poa.addPoint(x, y);
                
            }
        }
        private void fillPolygonB() {
            int s = points.size();
            pob = new Polygon();
            int i=0;
            for(;;) {
                int x = (int)(points.get(i).getX()+n);
                int y = (int)(points.get(i).getY()+n+200);
                pob.addPoint(x, y);
                i+=2;
                if(i%s==0)  break;
                else i%=s;
                
            }
        }
        public  static void main(String[] args ) {
            JFrame f = new JFrame("Test");
            f.setSize(300,600);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setLocationRelativeTo(null);
            f.add(new DrawStar());
            f.setVisible(true);
        }
        
    }
  • 相关阅读:
    MySQL 5.7 多主一从实现
    从 MySQL 全备的 SQL 文件中抽离出某张表的数据
    KUBERNETES 03:Pod 资源清单
    KUBERNETES 02:基本操作命令
    KUBERNETES 01:说明与安装
    DOCKER 08:搭建本地镜像仓库 Harbor
    DOCKER 07:docker swarm
    DOCKER 06:docker compose
    DOCKER 05:数据持久化
    DOCKER 04:容器资源限制和网络原理
  • 原文地址:https://www.cnblogs.com/qqjue/p/2628598.html
Copyright © 2011-2022 走看看