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);
        }
        
    }
  • 相关阅读:
    javascript的函数调用什么时候加括号、什么时候不加括号
    妙味——JS学前预热03
    妙味——JS学前预热02
    妙味——JS学前预热01
    springbootday06 mysql
    springboot04 Ajax json Jquery
    springboot02 Thymeleaf
    springbootDay03 cookie和session 购物车技术
    Linux 基本命令
    NodeJs06 高并发
  • 原文地址:https://www.cnblogs.com/qqjue/p/2628598.html
Copyright © 2011-2022 走看看