Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics;
- import java.util.Random;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author janek
- */
- public class Prostokąt extends Thread {
- Color k; // kolor prostokata
- int x, w, h, H; //x- współrzędna pozioma położenia, w- szerokość prostokąta, H- Wysokość panelu
- Random r = new Random();
- Random u= new Random();
- int dt;
- public Prostokąt(int x, int w, int H) {
- this.x = x;
- this.w = w;
- this.H = H;
- k = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)); // losowy kolor prostokąta
- dt = 500 + r.nextInt(1000);
- }
- void rysuj(Graphics g) {
- g.setColor(k);
- g.fillRect(x, H - h, w, h);
- }
- public void run() {
- while (true) {
- if ( animacja.ruch ) h = r.nextInt(200);
- try {
- Thread.sleep(dt); //uśpienie wątku na dt milisekund
- } catch (InterruptedException e) {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement