现在的位置: 首页 > 综合 > 正文

swing绘制直升机

2017年12月19日 ⁄ 综合 ⁄ 共 4965字 ⁄ 字号 评论关闭

 

  1. import java.awt.Color;  
  2. import java.awt.Frame;  
  3. import java.awt.Graphics;  
  4.  
  5. import javax.*;  
  6. //import javax.swing.JPanel;  
  7. import javax.swing.JFrame;  
  8. import javax.swing.JPanel;  
  9.  
  10.  
  11. public class Helicoper {  
  12.  
  13.     public Helicoper(){   
  14.         //this.  
  15.            
  16.     }     
  17.     public static void main(String[] args) {     
  18.         JFrame frame = new JFrame();    
  19.         frame.setSize(400,300);     
  20.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     
  21.         frame.setVisible(true);    
  22.         Panel panel = new Panel();     
  23.         frame.add(panel);     
  24.     }     
  25. }     
  26.     
  27.     
  28. class Panel extends JPanel {     
  29.     
  30.     public void paint(Graphics g) {     
  31.         super.paint(g);     
  32.         //着色     
  33.              
  34.         //后浆     
  35.         g.setColor(Color.CYAN);     
  36.         g.fillOval((15-12),(31-12),12*2,12*2);     
  37.         //前桨     
  38.         g.fillPolygon(new int[]{62,63,65,69,77,93,108}, new int[]{11,10,9,8,7,6,6}, 7);     
  39.         g.fillPolygon(new int[]{62,77,93,101,105,107,108}, new int[]{11,10,9,8,7,6,6}, 7);     
  40.                      
  41.         g.fillPolygon(new int[]{112,113,115,119,127,143,158}, new int[]{6,5,4,3,2,1,1}, 7);     
  42.         g.fillPolygon(new int[]{112,127,143,151,155,157,158}, new int[]{6,5,4,3,2,1,1}, 7);     
  43.          
  44.              
  45.         //飞机躯干     
  46.         g.setColor(Color.GREEN);     
  47.         g.fillPolygon(     
  48.                 new int[] { 158, 147, 139, 124, 120, 92, 76, 50,46,37,41, 14, 15, 75, 89, 142},     
  49.                 new int[] { 43,  34,  27,  23,  19,  19, 26, 28,25,25,28, 29, 33, 39, 51, 51},      
  50.                 16);     
  51.         g.fillArc(89+20, 52-(52-43)*2, (158-89)-20, (52-43)*2, 0, -70);     
  52.              
  53.         //机身     
  54.         g.setColor(Color.GRAY);     
  55.         g.fillPolygon(new int[]{87,123,124,74}, new int[]{22,22,24,26}, 4);     
  56.         g.fillArc(131-10, 38-(44-38), 10, (44-38)*2, 0, -90);     
  57.         g.fillPolygon(new int[]{74,81,131-10/2,131,124}, new int[]{26,44,44,38,24}, 5);     
  58.         g.fillPolygon(new int[]{54,45,37,46}, new int[]{31,31,25,25}, 4);     
  59.              
  60.         //尾翼     
  61.         g.fillPolygon(new int[]{24,17,14,13},  new int[]{28,21,21,28}, 4);     
  62.         g.fillArc(13,19,4,4,160,-180);     
  63.              
  64.         //前桨     
  65.         g.setColor(Color.RED);     
  66.         g.fillPolygon(new int[]{112,112,108,108}, new int[]{19,10,10,19}, 4);     
  67.         g.fillOval(108, (10-4), 4, 4);     
  68.              
  69.     
  70.         //飞机窗口     
  71.         g.setColor(Color.BLACK);     
  72.         g.fillPolygon(new int[]{147,133,128,139}, new int[]{34,34,25,27}, 4);     
  73.         g.fillPolygon(new int[]{87,123,120,92}, new int[]{22,22,19,19}, 4);     
  74.         g.fillPolygon(new int[]{129,120,116,124}, new int[]{35,35,26,24}, 4);     
  75.         g.fillPolygon(new int[]{113,117,108,102}, new int[]{26,35,35,26}, 4);     
  76.              
  77.         //飞机躯干     
  78.              
  79.              
  80.         g.drawPolyline(     
  81.                 new int[] { 158, 147, 139, 124, 120, 92, 76, 50,46,37,41, 14, 15, 75,89 ,142},      
  82.                 new int[] { 43, 34, 27, 23, 19, 19, 26, 28,25,25,28, 29, 33, 39, 51,51},     
  83.                 16);     
  84.         g.drawArc(89+20, 52-(52-43)*2, (158-89)-20, (52-43)*2, 0, -70);     
  85.     
  86.         //飞机头部     
  87.         g.drawPolyline(new int[]{147,133,128}, new int[]{34,34,25}, 3);     
  88.         //飞机机身     
  89.         g.drawPolyline(new int[]{87,123}, new int[]{22,22}, 2);     
  90.              
  91.     
  92.         g.drawPolyline(new int[]{74,124,131}, new int[]{26,24,38}, 3);     
  93.         g.drawArc(131-10, 38-(44-38), 10, (44-38)*2, 0, -90);     
  94.              
  95.         g.drawPolyline(new int[]{74,81,131-10/2}, new int[]{26,44,44}, 3);         
  96.         g.drawPolyline(new int[]{129,120,116}, new int[]{35,35,26}, 3);     
  97.         g.drawPolyline(new int[]{113,117,108,102}, new int[]{26,35,35,26}, 4);     
  98.              
  99.     
  100.         g.drawPolygon(new int[]{54,45,37,46}, new int[]{31,31,25,25}, 4);     
  101.              
  102.         g.drawLine(99, 26, 106, 44);     
  103.         g.drawLine(99, 32, 101, 32);     
  104.         g.drawLine(102, 39, 104, 39);     
  105.     
  106.         //飞机前桨             
  107.         g.drawPolyline(new int[]{112,112,108,108}, new int[]{19,10,10,19}, 4);         
  108.         g.drawOval(108, (10-4), 4, 4);     
  109.              
  110.         g.drawArc(108-(108-62)*2, 6-5, (108-62)*2, 5*2, 0, -90);     
  111.         g.drawArc(108-(108-62), 6, (108-62)*2, 5*2, 180, -90);     
  112.              
  113.         g.drawArc(112-(108-62), 6-5*2, (108-62)*2, 5*2, 0, -90);     
  114.         g.drawArc(112, 6-5, (108-62)*2, 5*2, 180, -90);     
  115.     
  116.         //飞机后浆 计算正切圆的切点坐标及外接正方形的起点坐标     
  117.     
  118.              
  119.         g.drawPolyline(new int[]{24,17}, new int[]{28,21}, 2);     
  120.         g.drawPolyline(new int[]{13,14}, new int[]{21,28},2);     
  121.         g.drawArc(13,19,4,4,160,-180);     
  122.     
  123.         g.drawOval((15-12),(31-12),12*2,12*2);     
  124.          
  125.         g.drawArc((15-8),(31-8),8*2,8*2,20,120);     
  126.         g.drawArc((15-8),(31-8),8*2,8*2,-20,-50);     
  127.         g.drawArc((15-8),(31-8),8*2,8*2,-90,-100);     
  128.         //飞机底座     
  129.         g.drawArc(108,51,16,16,0,90);     
  130.         g.drawArc(130,51,16,16,20,90);     
  131.         g.drawArc(55,(51-8+6),100,(16-6),-20,-70);         
  132.              
  133.     }     
  134.  
  135. }  

 

抱歉!评论已关闭.