swing绘制直升机

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

你可能感兴趣的:(swing)