Advertisement
Slapoguzov

Animation_Lab4_Pip

Nov 12th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.70 KB | None | 0 0
  1. class Animation implements Runnable
  2. {
  3.     private javax.swing.JFrame Fr;
  4.     private int R;
  5.     private int X, Y;
  6.     public Animation(javax.swing.JFrame Fr_, int R_, int x_, int y_)
  7.     {
  8.         Fr = Fr_;
  9.         R = R_;
  10.         X = x_;
  11.         Y = y_;
  12.     }
  13.     @Override
  14.     public void run() {
  15.        Graphics g = Fr.getGraphics();
  16.        Polygon trianglePol = new Polygon(new int[] {150,150,(150-10*(R/2))}, new int[] {150-10*R, 150,150}, 3);
  17.         try
  18.         {
  19.         for(int i=10*R/8; i > 1; i--)
  20.         {
  21.         sleep(40);  
  22.         paintR(g,R);
  23.         g.setColor(Color.GREEN);
  24.         g.drawOval(X-i/2, Y-i/2, i, i);
  25.         }
  26.         }
  27.         catch(InterruptedException e){
  28.         }
  29.     }
  30.  
  31.      public void paintR(Graphics g, int R)
  32.     {
  33.         paintFieldXY(g);
  34.         if(R !=0)
  35.         {
  36.         g.setColor(Color.black);
  37.         g.drawLine(145,150+10*R,155,150+10*R);
  38.         g.drawString("-R", 145-15, 150+10*R+10);
  39.         g.drawLine(145,150-10*(R/2),155,150-10*(R/2));
  40.         g.drawString("R", 145+15, 150-10*(R/2)-4);
  41.         g.drawLine(150+10*R,145,150+10*R,155);
  42.         g.drawString("R", 150+10*R, 170);
  43.         g.drawLine(150-10*R,145,150-10*R,155);
  44.         g.drawString("-R", 150-10*R-8, 145);
  45.        
  46.         g.setColor(Color.YELLOW);
  47.         Polygon trianglePol = new Polygon(new int[] {150,150,(150+10*(R/2))}, new int[] {150+10*R, 150,150}, 3);
  48.         g.drawPolygon(trianglePol);
  49.         g.drawRect(150, 150-5*R, R*10, R*5);
  50.         g.drawArc(150-R*10,150-R*10,R*20,R*20,180,90);
  51.         g.setColor(Color.BLACK);
  52.         g.fillPolygon(trianglePol);
  53.         g.fillRect(150, 150-5*R, R*10, R*5);
  54.         g.fillArc(150-R*10,150-R*10,R*20,R*20,180,90);
  55.         }
  56.         else
  57.         {
  58.           g.drawString("R", 153, 165);
  59.         }
  60.     }
  61.      
  62.       public void paintFieldXY(Graphics g)
  63.     {
  64.         g.clearRect(1, 1, 300, 300);
  65.         g.setColor(Color.black);
  66.          //Отрисовываем координатную плоскость
  67.          final int OX_X_1 = 40;
  68.          final int OX_X_2 = 270;
  69.          final int OX_Y = 150;
  70.          final int OY_X = 150;
  71.          final int OY_Y_1 = 60;
  72.          final int OY_Y_2 = 250;
  73.          g.drawLine(OY_X, OY_Y_1, OY_X, OY_Y_2);                //ось OY
  74.          g.drawLine(OX_X_1, OX_Y, OX_X_2, OX_Y);                //ось OX
  75.          g.drawString("Y", OY_X+5, OY_Y_1+5);                  //подписываем оси
  76.          g.drawString("X", OX_X_2-5, OX_Y-5);
  77.          g.drawLine(OY_X, OY_Y_1, OY_X+2, OY_Y_1+6);
  78.          g.drawLine(OY_X, OY_Y_1, OY_X-2, OY_Y_1+6);
  79.          g.drawLine(OX_X_2, OX_Y, OX_X_2-6, OX_Y-2);
  80.          g.drawLine(OX_X_2, OX_Y, OX_X_2-6, OX_Y+2);
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement