SHOW:
|
|
- or go back to the newest paste.
1 | http://uloz.to/xPk95m5o/netbeansmalovani-rar | |
2 | ||
3 | private final static int pocetPoli = 10; | |
4 | ||
5 | ||
6 | private void naMalujCtverce(int pocetCtvercu) { | |
7 | int rozmer = getStrana() / pocetCtvercu; | |
8 | ||
9 | Graphics grafika = this.getGraphics(); | |
10 | ||
11 | for (int i = 0; i <= rozmer * pocetCtvercu; i += rozmer) { | |
12 | for (int j = 0; j <= rozmer * pocetCtvercu; j += rozmer) { | |
13 | ||
14 | grafika.setColor(getBarva()); | |
15 | grafika.fillRect(i, j, rozmer, rozmer); | |
16 | ||
17 | try { | |
18 | Thread.sleep(100); | |
19 | } catch (InterruptedException ex) { | |
20 | Thread.currentThread().interrupt(); | |
21 | } | |
22 | } | |
23 | ||
24 | } | |
25 | ||
26 | } | |
27 | ||
28 | private int getStrana() { | |
29 | return Math.min(this.getWidth(), this.getHeight()); | |
30 | } | |
31 | ||
32 | private Color getBarva() { | |
33 | Random rand = new Random(); | |
34 | ||
35 | float r = rand.nextFloat(); | |
36 | float g = rand.nextFloat(); | |
37 | float b = rand.nextFloat(); | |
38 | ||
39 | return new Color(r, g, b); | |
40 | } | |
41 | ||
42 | @Override | |
43 | public void paint(Graphics g) { | |
44 | super.paint(g); //To change body of generated methods, choose Tools | Templates. | |
45 | naMalujCtverce(pocetPoli); | |
46 | } |