Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.82 KB | None | 0 0
  1. import java.awt.image.BufferStrategy;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.io.*;
  5.  
  6. public class Application extends Thread {
  7.     private Frame frame;
  8.     private Fractal fractal;
  9.     private BufferStrategy buffer;
  10.     private int x;
  11.     private int y;
  12.  
  13.     public Application(int x, int y, Frame frame, Fractal fractal, BufferStrategy buffer, int priority)
  14.     {
  15.         this.frame = frame;
  16.         this.fractal = fractal;
  17.         this.buffer = buffer;
  18.         this.x = x;
  19.         this.y = y;
  20.  
  21.         setPriority(priority);
  22.  
  23.         start();
  24.     }
  25.  
  26.     public static void main(String args[]) {
  27.         InputStreamReader Stream = new InputStreamReader(System.in);
  28.         BufferedReader buffer_console = new BufferedReader(Stream);
  29.  
  30.         int[] priority_data = new int[10];
  31.         System.out.print("[Priorytety animacji fraktali 1 - 10]\n");
  32.         for (int j = 0; j < 10; j++) {
  33.             System.out.print("Priorytet animacji #" + (j + 1) + ": ");
  34.             priority_data[j] = setInteger(buffer_console);
  35.         }
  36.  
  37.         Frame frame = new Frame("Aplikacja");
  38.  
  39.         Fractal fractal = new Fractal();
  40.         Fractal fractal2 = new Fractal();
  41.         BufferStrategy buffer = frame.getBufferStrategy();
  42.  
  43.         //for (int j = 0; j < 10; j++) {
  44.             for (int i = 0; i < 1001; i += 250) {
  45.                 fractal = new Fractal();
  46.                 fractal.setA(((250 + i) / 250));
  47.                 new Application(i, 0, frame, fractal, buffer, priority_data[((250 + i) / 250) - 1]);
  48.                 fractal2 = new Fractal();
  49.                 fractal2.setA(((250 + i) / 250) + 5);
  50.                 new Application(i, 250, frame, fractal2, buffer, priority_data[((250 + i) / 250) + 3]);
  51.             }
  52.         //}
  53.     }
  54.  
  55.     public void run()
  56.     {
  57.         if (this.buffer == null) {
  58.             this.frame.createBufferStrategy(1);
  59.             this.buffer = this.frame.getBufferStrategy();
  60.         }
  61.  
  62.         Graphics graphic_new = buffer.getDrawGraphics();
  63.         while (true) {
  64.             graphic_new.setColor(Color.WHITE);
  65.             graphic_new.clearRect(this.x, this.y, 250, 250);
  66.             graphic_new.fillRect(this.x, this.y, 250, 250);
  67.             graphic_new.setColor(Color.GREEN);
  68.             this.fractal.begin(graphic_new, this.x, this.y);
  69.  
  70.             try {
  71.                 Application.sleep(500);
  72.                 this.buffer.show();
  73.             } catch (InterruptedException error) { error.printStackTrace(); }
  74.         }
  75.     }
  76.  
  77.     public static int setInteger(BufferedReader buffer_console)
  78.     {
  79.         int value = 0;
  80.  
  81.         try {
  82.             value = Integer.parseInt(buffer_console.readLine());
  83.         } catch(IOException error) {
  84.             error.printStackTrace();
  85.             System.exit(0);
  86.         }
  87.  
  88.         return value;
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement