package mm.display;

import mm.structures.ColorField;
import mm.structures.ColorPixel;

import javax.swing.*;
import java.awt.*;

public class FieldPanel extends JPanel {

        private ColorField field;
        private ColorPixel[] colors;

        public FieldPanel(ColorField field) {
        this.field = field;
        this.colors = field.getColors();
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        long start = System.nanoTime();
        Rectangle bounds = g.getClipBounds();
        int n = field.getN();
        int elementSize = bounds.height / n;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                ColorPixel pixel = colors[field.getElement2D(i, j)];
                g.setColor(pixel.getColor());
                g.fillRect(j * elementSize, i * elementSize, elementSize, elementSize);
            }
        }
        System.out.printf("generiranje: %d\n", System.nanoTime() - start);
    }
}

@@ -455,48 +455,8 @@
 g);%0A
-        long start = System.nanoTime();%0A
     
@@ -885,77 +885,82 @@
     
+%7D%0A%0A
     
-System.out.printf(%22generiranje: %25d%5Cn%22, System.nanoTime() - start)
+public void setField(ColorField field) %7B%0A        this.field = field
 ;%0A  

add method to update field in FieldPanel