• 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);
        }
        
    }
  • 相关阅读:
    枚举和字符串之间的转换 [转帖]
    escape,encodeURI,encodeURIComponent函数比较[转帖]
    .net中的Provider模式 [转帖]
    ogg转到mp3
    四季养生(樊正伦教授)
    JavaScript高阶之路
    Python初识
    理解error和exception之间的区别(转)
    一些有用的话
    《爱在雨季》片尾曲
  • 原文地址:https://www.cnblogs.com/qqjue/p/2628598.html
Copyright © 2020-2023  润新知