Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1.  
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.util.Random;
  5.  
  6. /*
  7.  * To change this license header, choose License Headers in Project Properties.
  8.  * To change this template file, choose Tools | Templates
  9.  * and open the template in the editor.
  10.  */
  11. /**
  12.  *
  13.  * @author janek
  14.  */
  15. public class Prostokąt extends Thread {
  16.  
  17.     Color k; // kolor prostokata
  18.     int x, w, h, H; //x- współrzędna pozioma położenia, w- szerokość prostokąta, H- Wysokość panelu
  19.  Random r = new Random();
  20.  Random u= new Random();  
  21.  int dt;
  22.     public Prostokąt(int x, int w, int H) {
  23.         this.x = x;
  24.         this.w = w;
  25.         this.H = H;
  26.         k = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)); // losowy kolor prostokąta
  27.         dt = 500 + r.nextInt(1000);
  28.     }
  29.    
  30.  
  31.     void rysuj(Graphics g) {
  32.         g.setColor(k);
  33.         g.fillRect(x, H - h, w, h);
  34.     }
  35.  
  36.     public void run() {
  37.         while (true) {
  38.             if ( animacja.ruch ) h = r.nextInt(200);
  39.            
  40.             try {
  41.                 Thread.sleep(dt); //uśpienie wątku na dt milisekund
  42.             } catch (InterruptedException e) {
  43.             }
  44.         }
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement